Qantler entrevista experimenta
1. Obtenha três números e encontre o 2º máximo de importação java.util.scanner; classe pública SecondMax {public static void main (string[] args) {scanner sc = new scanner (system.in); int a = sc.nextInt (); int b = sc.nextInt (); int c = sc.nextInt (); int segundoMax; if ((a> = b && a <= c) || (a <= b && a >= c)) SecondMax = A; caso contrário, se ((b> = a && b <= c) || (b <= a && b >= c)) SecondMax = b; else segundoMax = c; System.out.println (“Segundo máximo:” + SecondMax); }} 2. Recursão- Encontre a soma dos dígitos de um número usando a recursão. importar java.util.scanner; classe pública SumDigits {public static int sumofdigits (int n) {if (n == 0) return 0; retornar n % 10 + sumofdigits (n / 10); } public static void main (string[] args) {scanner sc = new scanner (system.in); System.out.print (“Digite um número:”); int num = sc.nextInt (); System.out.println (“Soma dos dígitos:” + SUMOFDIGITS (NUM)); }} 3. Obtenha números até ‘q’, soma e contagem importar java.util.scanner; classe pública SumCount {public static void main (string[] args) {scanner sc = new scanner (system.in); int sum = 0, count = 0; while (true) {string input = sc.NextLine (); // por exemplo, 10, string w[] partes = input.split (“,”); INT número = Integer.parseint (peças[0]); char ch = peças[1].Charat (0); soma += número; contagem ++; if (ch == ‘q’) quebra; } System.out.println (“count:” + count); System.out.println (“Sum:” + Sum); }} 4. Obtenha números, validar, imprimir min & max importar java.util.*; classe pública minmaxvalidação {public static void main (string[] args) {scanner sc = new scanner (system.in); Lista
System.out.println(“Error: Negative number not allowed”);
continue;
}
if (n > 999) {System.out.println (“Erro: Número com mais de 3 dígitos não permitidos”); continuar; } nums.add (n); if (nums.size () == 5) quebra; // Pare após 5 números por exemplo} System.out.println (“Numbers:” + nums); System.out.println (“min:” + collectionS.min (nums)); System.out.println (“max:” + collection.max (nums)); }} 5. Animal, cão, humano (oop – substituição do método) Animal {void whoami () {System.out.println (“Animal”); }} classe cão estende Animal {@Override void whoami () {System.out.println (“Dog”); }} classe Human estende Animal {@Override void whoami () {System.out.println (“Human”); }} Teste de classe pública {public static void main (string[] args) {animal a = novo animal (); Animal d = novo cachorro (); Animal H = novo humano (); a.Whoami (); // animal d.whoami (); // cachorro h.whoami (); // humano}} 6. Raio do círculo → Diâmetro e área importar java.util.scanner; public class Circle {public static void main (string[] args) {scanner sc = new scanner (system.in); duplo r = sc.nextDouble (); diâmetro duplo = 2 * r; área dupla = math.pi * r * r; System.out.println (“diâmetro:” + diâmetro); System.out.println (“área:” + área); }} 7. SQL – Criar tabelas Criar alunos da tabela (Id int Primary Key, Nome Varchar (50), Gênero Varchar (10), Class Int); Criar Marcas de Tabela (ID Int, Tamil Int, Eng Int, Maths Int, Science Int, History Int, Foreign Key (ID) Referências dos alunos (ID)); – Criar alunos Tabela Criar alunos da tabela (Id int Primary Key, Nome Varchar (50), Gênero Varchar (10), Class Int); – Criar marcas Tabela Criar marcas de tabela (Id int Primary Key, Tamil Int, Eng Int, Maths Int, Science Int, History Int); – Insira o exemplo de inserção de dados nos valores dos alunos (1, ‘Vicky’, ‘masculino’, 10); Inserir em valores de marcas (1, 45, 50, 60, 55, 48); – Marcas totais por aluno Select s.id, s.name, (M.Tamil + M.Eng + M.Maths + M.Science + M.History) como total das juntas dos alunos Junção M no s.id = M.id; – Count Pass Students (classe 10, marca de aprovação 40) Selecione a contagem
Tabela de alunos | EU IA | Nome | Aula |
---|---|---|---|
Gênero | 1 | Vicky | 10 |
Macho | 2 | Malini | 8 |
Fêmea
Enviar[] 11. Escreva a entrada do usuário para arquivo importar java.io.*; importar java.util.scanner; public class Writefile {public static void main (string[] args) lança exceção {scanner sc = new scanner (system.in); FileWriter FW = new FileWriter (“Output.txt”); Dados da String = SC.NextLine (); fw.write (dados); fw.close (); }} 12. Leia o arquivo e a linha de contagem, char, palavras importam java.io.*; classe pública FileReadCount {public Static Void Main (String[] args) lança exceção {bufferredader Br = new BufferredReader (new FileReader (“output.txt”)); int linhas = 0, palavras = 0, chars = 0; Linha de string; while ((line = Br.readline ())! = null) {linhas ++; chars += line.length (); palavras += line.split (“\\ s +”). comprimento; } Br.Close (); System.out.println (“linhas:”+linhas); System.out.println (“palavras:”+palavras); System.out.println (“chars:”+chars); }} 13. Classe de pilha (push, pop, peek) pilha {int[size]arr; int topo, capacidade; Stack (Int Size) {arr = new Int[++top] ; capacidade = tamanho; top = -1; } void push (int x) {if (top == capacidade-1) System.out.println (“Overflow”); caso contrário, arr[top–]= x; } int pop () {if (top == -1) {System.out.println (“subflow”); retornar -1; } retornar arr[top]; } int peek () {if (top == -1) {System.out.println (“vazio”); retornar -1; } retornar arr; }}
Fonte