Jump to content

Renan Alves

Membros
  • Contagem de Conteúdo

    62
  • Ingressou

  • Última visita

  • Dias Ganhos

    1

Tudo que foi postado por Renan Alves

  1. beecrowd | 1067 Odd Numbers Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read an integer value X (1 <= X <= 1000). Then print the odd numbers from 1 to X, each one in a line, including X if is the case. Input The input will be an integer value. Output Print all odd values between 1 and X, including X if is the case. import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int n, i; n = sc.nextInt(); for(i = 1; i <= n; i++) { if(i % 2 != 0) { System.out.println(i); } } sc.close(); } }
  2. beecrowd | 1066 Even, Odd, Positive and Negative Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Make a program that reads five integer values. Count how many of these values are even, odd, positive and negative. Print these information like following example. Input The input will be 5 integer values. Output Print a message like the following example with all letters in lowercase, indicating how many of these values are even, odd, positive and negative. import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int n, i, impa = 0, par = 0, negativo = 0, positivo = 0; for(i = 1; i <= 5; i++) { n = sc.nextInt(); if(n < 0 || n > 0) { if(n > 0) { positivo++; } else { negativo++; } } if(n % 2 != 0 || n % 2 == 0) { if(n % 2 != 0) { impa++; } else { par++; } } } System.out.println(par + " valor(es) par(es)"); System.out.println(impa + " valor(es) impar(es)"); System.out.println(positivo + " valor(es) positivo(s)"); System.out.println(negativo + " valor(es) negativo(s)"); sc.close(); } }
  3. beecrowd | 1065 Even Between five Numbers Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Make a program that reads five integer values. Count how many of these values are even and print this information like the following example. Input The input will be 5 integer values. Output Print a message like the following example with all letters in lowercase, indicating how many even numbers were typed. Resolução: import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int n, i, p = 0; for(i = 1; i <= 5; i++) { n = sc.nextInt(); if(n % 2 == 0) { p++; } } System.out.println(p + " valores pares"); sc.close(); } }
  4. beecrowd | 1064 Positives and Average Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read 6 values that can be floating point numbers. After, print how many of them were positive. In the next line, print the average of all positive values typed, with one digit after the decimal point. Input The input consist in 6 numbers that can be integer or floating point values. At least one number will be positive. Output The first output value is the amount of positive numbers. The next line should show the average of the positive values typed. Resolução: import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double n, positivo = 0, media = 0; for(int i = 1; i <= 6; i++) { n = sc.nextDouble(); if(n >= 0) { media += n; positivo++; } } media /= positivo; System.out.printf("%.0f valores positivos\n", positivo); System.out.printf("%.1f\n", media); } }
  5. beecrowd | 1061 Event Time Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Peter is organizing an event in his University. The event will be in April month, beginning and finishing within April month. The problem is: Peter wants to calculate the event duration in seconds, knowing obviously the begin and the end time of the event. You know that the event can take from few seconds to some days, so, you must help Peter to compute the total time corresponding to duration of the event. Input The first line of the input contains information about the beginning day of the event in the format: “Dia xx”. The next line contains the start time of the event in the format presented in the sample input. Follow 2 input lines with same format, corresponding to the end of the event. Output Your program must print the following output, one information by line, considering that if any information is null for example, the number 0 must be printed in place of W, X, Y or Z: W dia(s) X hora(s) Y minuto(s) Z segundo(s) Obs: Consider that the event of the test case have the minimum duration of one minute. “dia” means day, “hora” means hour, “minuto” means minute and “Segundo” means second in Portuguese. Resolução: import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); String d, p; int dia1, hora1, minuto1, segundo1; int dia2, hora2, minuto2, segundo2; //hora inicial; d = sc.next(); dia1 = sc.nextInt(); hora1 = sc.nextInt(); p = sc.next(); minuto1 = sc.nextInt(); p = sc.next(); segundo1 = sc.nextInt(); //fim do evento; d = sc.next(); dia2 = sc.nextInt(); hora2 = sc.nextInt(); p = sc.next(); minuto2 = sc.nextInt(); p = sc.next(); segundo2 = sc.nextInt(); int inicio = 24 * 60 * 60 * dia1 + hora1 * 60 * 60 + minuto1 * 60 + segundo1; int fim = 24 * 60 * 60 * dia2 + hora2 * 60 * 60 + minuto2 * 60 + segundo2; int fim_Do_Evento = (fim - inicio) / (24 * 60 * 60); int dia = (fim - inicio) % (24 * 60 * 60); int hora = dia / (60 * 60); int resto = dia % (60 * 60); int minuto = resto / 60; int segundo = resto % 60; System.out.println(fim_Do_Evento + " dia(s)"); System.out.println(hora + " hora(s)"); System.out.println(minuto + " minuto(s)"); System.out.println(segundo + " segundo(s)"); sc.close(); } }
  6. beecrowd | 1060 Positive Numbers Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Write a program that reads 6 numbers. These numbers will only be positive or negative (disregard null values). Print the total number of positive numbers. Input Six numbers, positive and/or negative. Output Print a message with the total number of positive numbers. Resolução: import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double n; int positivo = 0; for (int i = 1; i <= 6; i++) { n = sc.nextDouble(); if (n >= 0) { positivo++; } } System.out.println(positivo + " valores positivos"); sc.close(); } }
  7. beecrowd | 1059 Even Numbers Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Write a program that prints all even numbers between 1 and 100, including them if it is the case. Input In this extremely simple problem there is no input. Output Print all even numbers between 1 and 100, including them, one by row. Resolução: public class Main { public static void main(String[] args) { for(int i = 1; i <= 100; i++) { if(i % 2 == 0) { System.out.println(i); } } } }
  8. beecrowd | 1052 Month Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read an integer number between 1 and 12, including. Corresponding to this number, you must print the month of the year, in english, with the first letter in uppercase. Input The input contains only an integer number. Output Print the name of the month according to the input number, with the first letter in uppercase. Sintaxe opcional - Switch case: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int mounth; String mes; switch(mounth = sc.nextInt()) { case 1: mes = "January"; break; case 2: mes = "February"; break; case 3: mes = "March"; break; case 4: mes = "April"; break; case 5: mes = "May"; break; case 6: mes = "June"; break; case 7: mes = "July"; break; case 8: mes = "August"; break; case 9: mes = "September"; break; case 10: mes = "October"; break; case 11: mes = "November"; break; default: mes = "December"; } System.out.println(mes); sc.close(); } }
  9. Parece que há um erro na chamada do método consultar() na classe ProcessoDAO. Na classe Botão, você está tentando chamar o método consultar(parte1) da classe ProcessoDAO, mas na classe ProcessoDAO, o método correspondente é chamado getProcesso(parte1). Para corrigir isso, você pode alterar a chamada do método na classe Botão para getProcesso(parte1): javaCopy code Processo processo = dao.getProcesso(parte1); Além disso, é importante verificar se a conexão com o banco de dados está sendo estabelecida corretamente na classe ProcessoDAO antes de executar a consulta. Certifique-se de que pst está sendo inicializado com uma conexão preparada contendo o SQL correto. Outro ponto a ser observado é que parece haver um erro na definição do tipo de dados para os atributos distribuicao, num_proc e vara na classe Processo. Na classe Processo, esses atributos são definidos como int, mas na classe ProcessoDAO, ao recuperar os valores do banco de dados, eles são tratados como String. Certifique-se de que o tipo de dados na classe Processo corresponda ao tipo de dados no banco de dados. Além disso, certifique-se de que os índices de parâmetros no método setString() correspondam aos parâmetros corretos no seu SQL. No seu caso, você está passando 6 como o índice de parâmetro, mas você só tem um parâmetro no seu SQL (?), então o índice deve ser 1. Assumindo que pst é uma instância de PreparedStatement, você deve configurar o parâmetro da seguinte forma: javaCopy code pst.setString(1, parte1); Essas correções devem ajudar a resolver o problema que você está enfrentando. Certifique-se também de verificar se não há outros erros no código que possam estar afetando o funcionamento correto.
  10. beecrowd | 1051 Taxes By Neilor Tonin, URI Brasil Timelimit: 1 In an imaginary country called Lisarb, all the people are very happy to pay their taxes because they know that doesn’t exist corrupt politicians and the taxes are used to benefit the population, without any misappropriation. The currency of this country is Rombus, whose symbol is R$. Read a value with 2 digits after the decimal point, equivalent to the salary of a Lisarb inhabitant. Then print the due value that this person must pay of taxes, according to the table below. Remember, if the salary is R$ 3,002.00 for example, the rate of 8% is only over R$ 1,000.00, because the salary from R$ 0.00 to R$ 2,000.00 is tax free. In the follow example, the total rate is 8% over R$ 1000.00 + 18% over R$ 2.00, resulting in R$ 80.36 at all. The answer must be printed with 2 digits after the decimal point. Input The input contains only a float-point number, with 2 digits after the decimal point. Output Print the message "R$" followed by a blank space and the total tax to be payed, with two digits after the decimal point. If the value is up to 2000, print the message "Isento". Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double valor, taxas = 0; valor = sc.nextDouble(); if(valor >= 0 && valor <= 2000.0) { System.out.println("Isento"); } else if(valor > 2000.0 && valor <= 3000.0) { taxas = (valor - 2000) / 100.0 * 8.0; } else if(valor > 3000.0 && valor <= 4500.0) { taxas = (valor - 3000.0) / 100.0 * 18.0 + 1000.0 / 100.0 * 8.0; } else { taxas = (valor - 4500.0) / 100.0 * 28.0 + 1500.0 / 100 * 18.0 + 1000.0 / 100.0 * 8.0; } if(taxas > 0.0) { System.out.printf("R$ %.2f\n" , taxas); } sc.close(); } }
  11. beecrowd | 1050 DDD Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read an integer number that is the code number for phone dialing. Then, print the destination according to the following table: 61 - Brasilia 71 - Salvador 11 - Sao Paulo 21 - Rio de Janeiro 32 - Juiz de Fora 19 - Campinas 27 - Vitoria 31 - Belo Horizonte qualquer ddd digitado fora desse escopo, o resultado vai ter que ser "DDD nao cadastrado". If the input number isn’t found in the above table, the output must be: DDD nao cadastrado That means “DDD not found” in Portuguese language. Input The input consists in a unique integer number. Output Print the city name corresponding to the input DDD. Print DDD nao cadastrado if doesn't exist corresponding DDD to the typed number. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int ddd = sc.nextInt(); String estado; if(ddd == 61) { estado = "Brasilia"; } else if(ddd == 71) { estado = "Salvador"; } else if(ddd == 11) { estado = "Sao Paulo"; } else if(ddd == 21) { estado = "Rio de Janeiro"; } else if(ddd == 32) { estado = "Juiz de Fora"; } else if(ddd == 19) { estado = "Campinas"; } else if(ddd == 27) { estado = "Vitoria"; } else if(ddd == 31) { estado = "Belo Horizonte"; } else { estado = "DDD nao cadastrado"; } System.out.println(estado); sc.close(); } }
  12. beecrowd | 1048 Salary Increase By Neilor Tonin, URI Brazil Timelimit: 1 The company ABC decided to give a salary increase to its employees, according to the following table: Salary Readjustment Rate 0 - 400.00 15% 400.01 - 800.00 12% 800.01 - 1200.00 10% 1200.01 - 2000.00 7% Above 2000.00 4% Read the employee's salary, calculate and print the new employee's salary, as well the money earned and the increase percentual obtained by the employee, with corresponding messages in Portuguese, as the below example. Input The input contains only a floating-point number, with 2 digits after the decimal point. Output Print 3 messages followed by the corresponding numbers (see example) informing the new salary, the among of money earned (both must be shown with 2 decimal places) and the percentual obtained by the employee. Note: Novo salario: means "New Salary" Reajuste ganho: means "Money earned" Em percentual: means "In percentage" Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double salario, porcentagem, soma, percentual; salario = sc.nextDouble(); if(salario >= 0 && salario <= 400.0) { porcentagem = 15.0; } else if (salario > 400.0 && salario <= 800.0) { porcentagem = 12.0; } else if (salario > 800.0 && salario <= 1200.0) { porcentagem = 10.0; } else if (salario > 1200.0 && salario <= 2000.0) { porcentagem = 7.0; } else { porcentagem = 4.0; } percentual = (salario / 100.0) * porcentagem; soma = percentual + salario; System.out.printf("Novo salario: %.2f\n", soma); System.out.printf("Reajuste ganho: %.2f\n", percentual); System.out.printf("Em percentual: %.0f %%\n", porcentagem); sc.close(); } } Obs: para escrever o simbolo de %, utilizamos %%.
  13. beecrowd | 1047 Game Time with Minutes Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read the start time and end time of a game, in hours and minutes (initial hour, initial minute, final hour, final minute). Then print the duration of the game, knowing that the game can begin in a day and finish in another day, Obs.: With a maximum game time of 24 hours and the minimum game time of 1 minute. Input Four integer numbers representing the start and end time of the game. Output Print the duration of the game in hours and minutes, in this format: “O JOGO DUROU XXX HORA(S) E YYY MINUTO(S)” . Which means: the game lasted XXX hour(s) and YYY minutes. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int hora1, minuto1, hora2, minuto2, inicio, fim, duracao, hora, minuto; hora1 = sc.nextInt(); minuto1 = sc.nextInt(); hora2 = sc.nextInt(); minuto2 = sc.nextInt(); /* Converter horas em minutos */ inicio = hora1 * 60 + minuto1; fim = hora2 * 60 + minuto2; if(inicio < fim) { duracao = fim - inicio; // subtração do fim pelo inicio do evento. } else { duracao = (60 * 24 - inicio) + fim; // multiplicar as horas por minuto e subtrair pelos minutos do inicio. } hora = duracao / 60; //converter minutos em horas minuto = duracao % 60; // sobra da conversao dos minutos para horas, a quais a sobra é considerada minuto. System.out.println("O JOGO DUROU " + hora + " HORA(S) E " + minuto + " MINUTO(S)"); sc.close(); } }
  14. beecrowd | 1046 Game Time Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read the start time and end time of a game, in hours. Then calculate the duration of the game, knowing that the game can begin in a day and finish in another day, with a maximum duration of 24 hours. The message must be printed in portuguese “O JOGO DUROU X HORA(S)” that means “THE GAME LASTED X HOUR(S)” Input Two integer numbers representing the start and end time of a game. Output Print the duration of the game as in the sample output. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int inicio, fim, tempo; int dia1 = sc.nextInt(); int dia2 = sc.nextInt(); if(dia1 < dia2) { tempo = dia2 - dia1; } else { tempo = 24 - dia1 + dia2; } System.out.println("O JOGO DUROU " + tempo + " HORA(S)"); } }
  15. Ou você pode fazer como o Vinicius falou, ou você pode criar um outro array unidimensional para receber os números pares e os números impares. assim você conserva o array original.
  16. beecrowd | 1045 Triangle Types Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read 3 double numbers (A, B and C) representing the sides of a triangle and arrange them in decreasing order, so that the side A is the biggest of the three sides. Next, determine the type of triangle that they can make, based on the following cases always writing an appropriate message: if A ≥ B + C, write the message: NAO FORMA TRIANGULO if A2 = B2 + C2, write the message: TRIANGULO RETANGULO if A2 > B2 + C2, write the message: TRIANGULO OBTUSANGULO if A2 < B2 + C2, write the message: TRIANGULO ACUTANGULO if the three sides are the same size, write the message: TRIANGULO EQUILATERO if only two sides are the same and the third one is different, write the message: TRIANGULO ISOSCELES Input The input contains three double numbers, A (0 < A) , B (0 < B) and C (0 < C). Output Print all the classifications of the triangle presented in the input. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double a, b, c; double A, B, C; a = sc.nextDouble(); b = sc.nextDouble(); c = sc.nextDouble(); A = Math.max(a, Math.max(b, c)); B = 0; C = 0; if(A == a) { B = Math.max(b, c); C = Math.min(b, c); } if(A == b) { B = Math.max(a, c); C = Math.min(a, c); } if(A == c) { B = Math.max(a, b); C = Math.min(a, b); } if(A >= (B + C)) { System.out.println("NAO FORMA TRIANGULO"); } else if(A * A == B * B + C * C) { System.out.println("TRIANGULO RETANGULO"); } else if(A * A > B * B + C * C) { System.out.println("TRIANGULO OBTUSANGULO"); } else { System.out.println("TRIANGULO ACUTANGULO"); } if(A == B && B == C) { System.out.println("TRIANGULO EQUILATERO"); } else if(A == B && A != C|| A == C && A != B || B == C && B != A){ System.out.println("TRIANGULO ISOSCELES"); } sc.close(); } }
  17. import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.format.ResolverStyle; import java.util.List; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; public class SuaClasse { // Outros métodos da classe... // Método Buscar vendas por período // É necessário fazer a conversão de datas // Primeiro passo: Receber a data public void buscarVendasPorPeriodo() { if (TxtCodCliente.getText().isEmpty() && TxtNome.getText().isEmpty()) { JOptionPane.showMessageDialog(null, "Você deve informar o código ou o nome do Cliente que deseja pesquisar !", "Aviso!!!", JOptionPane.WARNING_MESSAGE); return; } if (TxtDataInicial.getText().equals(" / / ") || TxtDataFinal.getText().equals(" / / ")) { JOptionPane.showMessageDialog(null, "Você deve informar o período em que deseja pesquisar !", "Aviso!!!", JOptionPane.WARNING_MESSAGE); return; } try { DateTimeFormatter formato = DateTimeFormatter.ofPattern("dd/MM/yyyy") .withResolverStyle(ResolverStyle.STRICT); String frmPgto = ""; String nome = "%" + TxtNome.getText() + "%"; VendasDAO dao = new VendasDAO(); LocalDate dataInicio = LocalDate.parse(TxtDataInicial.getText(), formato); LocalDate dataFim = LocalDate.parse(TxtDataFinal.getText(), formato); if (radioBtnDin.isSelected()) { frmPgto = "Dinheiro"; } else if (radioBtnCartao.isSelected()) { frmPgto = "Cartão"; } else if (radioBtnCheque.isSelected()) { frmPgto = "Cheque"; } else if (radioBtnNota.isSelected()) { frmPgto = "Outros"; } String codigo = TxtCodCliente.getText(); if (!codigo.isEmpty()) { int codCliente = Integer.parseInt(codigo); List<Vendas> lista = dao.listarVendasPorClienteNoPeriodo(codCliente, frmPgto, dataInicio, dataFim); atualizarTabela(lista); } else { List<Vendas> lista = dao.listarVendasPorClientePorNome(nome, frmPgto, dataInicio, dataFim); atualizarTabela(lista); } } catch (DateTimeParseException e) { // data inválida JOptionPane.showMessageDialog(null, "Data inválida. Certifique-se de inserir no formato dd/MM/yyyy.", "Erro", JOptionPane.ERROR_MESSAGE); } } private void atualizarTabela(List<Vendas> lista) { DefaultTableModel dados = (DefaultTableModel) TabelaHistorico.getModel(); dados.setNumRows(0); for (Vendas v : lista) { dados.addRow(new Object[]{ v.getId(), v.getData_venda(), v.getCliente().getNome(), v.getTotal_venda(), v.getObservacao() }); } } }
  18. beecrowd | 1044 Multiples Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read two integer values (A and B). After, the program should print the message "Sao Multiplos" (are multiples) or "Nao sao Multiplos" (aren’t multiples), corresponding to the read values. Input The input has two integer numbers. Output Print the relative message to the input as stated above. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); if(a % b == 0 || b % a == 0) { System.out.println("Sao Multiplos"); } else { System.out.println("Nao sao Multiplos"); } sc.close(); } }
  19. beecrowd | 1043 Triangle Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read three point floating values (A, B and C) and verify if is possible to make a triangle with them. If it is possible, calculate the perimeter of the triangle and print the message: Perimetro = XX.X If it is not possible, calculate the area of the trapezium which basis A and B and C as height, and print the message: Area = XX.X Input The input file has tree floating point numbers. Output Print the result with one digit after the decimal point. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double a, b, c, resultado; a = sc.nextDouble(); b = sc.nextDouble(); c = sc.nextDouble(); if(a + b > c && a + c > b && b + c > a) { resultado = a + b + c; System.out.printf("Perimetro = %.1f\n", resultado); } else { resultado = (a + b) * c / 2.0; System.out.printf("Area = %.1f\n", resultado); } sc.close(); } }
  20. beecrowd | 1042 Simple Sort Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed. Input The input contains three integer numbers. Output Present the output as requested above. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int a, b, c, menor, medio, maior; a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); if(a > b && a > c) { maior = a; if(b > c) { medio = b; menor = c; } else { medio = c; menor = b; } } else if(b > c) { maior = b; if(c > a) { medio = c; menor = a; } else { medio = a; menor = c; } } else { maior = c; if(b > a) { medio = b; menor = a; } else { medio = a; menor = b; } } System.out.println(menor); System.out.println(medio); System.out.println(maior); System.out.println(); System.out.println(a); System.out.println(b); System.out.println(c); sc.close(); } }
  21. Ficou ótimo também, reduz um pouco a leitura do programa
  22. beecrowd | 1041 Coordinates of a Point Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Write an algorithm that reads two floating values (x and y), which should represent the coordinates of a point in a plane. Next, determine which quadrant the point belongs, or if you are at one of the Cartesian axes or the origin (x = y = 0). https://resources.beecrowd.com.br/gallery/images/problems/UOJ_1041.png If the point is at the origin, write the message "Origem". If the point is at X axis write "Eixo X", else if the point is at Y axis write "Eixo Y". Input The input contains the coordinates of a point. Output The output should display the quadrant in which the point is. Resolução: import java.util.Locale; import java.util.Scanner; public class Exercicio_7 { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); double x, y; x = sc.nextDouble(); y = sc.nextDouble(); if(x == 0 && y == 0) { System.out.println("Origem"); } else if(x == 0) { System.out.println("Eixo Y"); } else if(y == 0) { System.out.println("Eixo X"); } else if(x > 0 && y > 0) { System.out.println("Q1"); } else if(x < 0 && y > 0) { System.out.println("Q2"); } else if(x < 0 && y < 0) { System.out.println("Q3"); } else { System.out.println("Q4"); } sc.close(); } }
  23. beecrowd | 1040 Average 3 Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read four numbers (N1, N2, N3, N4), which one with 1 digit after the decimal point, corresponding to 4 scores obtained by a student. Calculate the average with weights 2, 3, 4 e 1 respectively, for these 4 scores and print the message "Media: " (Average), followed by the calculated result. If the average was 7.0 or more, print the message "Aluno aprovado." (Approved Student). If the average was less than 5.0, print the message: "Aluno reprovado." (Reproved Student). If the average was between 5.0 and 6.9, including these, the program must print the message "Aluno em exame." (In exam student). In case of exam, read one more score. Print the message "Nota do exame: " (Exam score) followed by the typed score. Recalculate the average (sum the exam score with the previous calculated average and divide by 2) and print the message “Aluno aprovado.” (Approved student) in case of average 5.0 or more) or "Aluno reprovado." (Reproved student) in case of average 4.9 or less. For these 2 cases (approved or reproved after the exam) print the message "Media final: " (Final average) followed by the final average for this student in the last line. Input The input contains four floating point numbers that represent the students' grades. Output Print all the answers with one digit after the decimal point. float = é usado quando você necessita de mais precisão nos cálculos com casas decimais. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); float nota1, nota2, nota3, nota4, nota5, media; nota1 = sc.nextFloat(); nota2 = sc.nextFloat(); nota3 = sc.nextFloat(); nota4 = sc.nextFloat(); media = (nota1 * 2f + nota2 * 3f + nota3 * 4f + nota4) / 10f; if(media >= 7f) { System.out.printf("Media: %.1f\n", media); System.out.println("Aluno aprovado."); } else if(media < 5f) { System.out.printf("Media: %.1f\n", media); System.out.println("Aluno reprovado."); } else { System.out.printf("Media: %.1f", media); System.out.println("\nAluno em exame."); nota5 = sc.nextFloat(); System.out.printf("Nota do exame: %.1f\n", nota5); media += nota5; media /= 2f; if(media >= 5f) { System.out.println("Aluno aprovado."); System.out.printf("Media final: %.1f\n", media); } else { System.out.println("Aluno reprovado."); System.out.printf("Media final: %.1f\n", media); } } sc.close(); } }
  24. beecrowd | 1038 Snack Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Using the following table, write a program that reads a code and the amount of an item. After, print the value to pay. This is a very simple program with the only intention of practice of selection commands. https://resources.beecrowd.com.br/gallery/images/problems/UOJ_1038_en.png Input The input file contains two integer numbers X and Y. X is the product code and Y is the quantity of this item according to the above table. Output The output must be a message "Total: R$ " followed by the total value to be paid, with 2 digits after the decimal point. Resolução: import java.util.Scanner; import java.util.Locale; public class Main { public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int codigo, quantidade; double produto; codigo = sc.nextInt(); quantidade = sc.nextInt(); if(codigo == 1) { produto = quantidade * 4.0; } else if(codigo == 2) { produto = quantidade * 4.5; } else if(codigo == 3) { produto = quantidade * 5.0; } else if(codigo == 4) { produto = quantidade * 2.0; } else { produto = quantidade * 1.5; } System.out.printf("Total: R$ %.2f\n", produto); sc.close(); } }
  25. Começando a segunda pagina de exercícios do https://judge.beecrowd.com/en
×
×
  • Create New...