Renan Alves Postado Fevereiro 4 Compartilhar Postado Fevereiro 4 (editado) Olá, me chamo Renan Alves e atualmente estou estudando JAVA - ORIENTADO A OBJETOS(J.O.O), tenho mais de 120 exercícios resolvidos em lógica de programação no https://www.beecrowd.com.br/judge/en, e vou compartilhar com vocês os exercícios até onde eu concluir. Ainda não utilizo o github, então irei postar aqui os códigos já prontos para aqueles a qual estão no mesmo barco que eu, "O inicio"! Editado Fevereiro 4 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 4 Autor(a) Compartilhar Postado Fevereiro 4 beecrowd | 1000 Hello World! Jean Bez, beecrowd Brasil Timelimit: 1 Welcome to beecrowd! Your first program in any programming language is usually "Hello World!". In this first problem all you have to do is print this message on the screen. Input This problem has no input. Output You must print the message Hello World! and then the endline as shown below. Resolução: public class Main { public static void main(String[] args) { System.out.println("Hello World!"); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 4 Autor(a) Compartilhar Postado Fevereiro 4 (editado) beecrowd | 1001 Extremely Basic Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read 2 variables, named A and B and make the sum of these two variables, assigning its result to the variable X. Print X as shown below. Print endline after the result otherwise you will get “Presentation Error”. Input The input file will contain 2 integer numbers. Output Print the letter X (uppercase) with a blank space before and after the equal signal followed by the value of X, according to the following example. Obs.: don't forget the endline after all. Resolução: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a, b, x; a = sc.nextInt(); b = sc.nextInt(); x = a + b; System.out.println("X = " + x); } } Editado Fevereiro 4 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 4 Autor(a) Compartilhar Postado Fevereiro 4 (editado) Beecrowd | 1002 Area of a Circle Adapted by Neilor Tonin, URI Brazil Timelimit: 1 The formula to calculate the area of a circumference is defined as A = π . R2. Considering to this problem that π = 3.14159: Calculate the area using the formula given in the problem description. Input The input contains a value of floating point (double precision), that is the variable R. Output Present the message "A=" followed by the value of the variable, as in the example bellow, with four places after the decimal point. Use all double precision variables. Like all the problems, don't forget to print the end of line after the result, otherwise you will receive "Presentation Error". 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 r, pi = 3.14159, a; r = sc.nextDouble(); a = Math.pow(r, 2) * pi; System.out.printf("A=%.4f\n", a); } } No caso desse programa, eu utilizei o Scanner, que te dá liberdade para digitar no console para a maquina ler, de acordo com a variável! E usei também o Locale, a qual te permite habilitar as regras gramaticais de cada pais, eu sempre utilizo o US(United States) no locale, para que eu possa digitar números reais sem utilizar virgulas para separar os números. Com idioma BR, você utiliza "virgula" para separar os números, exemplo: 2,0... quando você digitar no console. Com idioma US, você utiliza "ponto" para separar os números, exemplo: 2.0... quando você digitar no console. Também utilizei o Math.pow(a , n) , ele te permite a potencializar a base(a) por tantas vezes o expoente(n), para resumir, supomos que o numero 2 seja representado pela letra A, e seu expoente seja 4, então em vez de você criar uma linha de: A * A * A * A, apenas precisaria do Math.pow(A , 4);. E na hora da maquina escrever para você, utilizei o System.out.printf, esse modo de leitura te permite formatar tudo que está dentro dele de acordo com a variável: String palavra = %s; Int inteiro = %d; double / float real = %.(algum numero).f; A quantidade de números dentro do "algum numero", ler para você a quantidade de números após a parte inteira, ou seja, depois da virgula. Exemplo: parte inteira , decimo centésimos milésimos. = 4.123 Se você colocar %.0f, ele entrega apenas o valor inteiro; Char letra = %c; Para pular a linha, você pode usar %n ou \n; %n = pula linha com espaço após a leitura. \n = não deixa espaço após a leitura. e para ler tudo, basta apenas fazer tudo Concatenado entre aspas, seguido do nome dado a cada variável, exemplo: System.out.printf("%s, %d, %.4f, %c%n", palavra, inteiro, real, letra) ; E sobre boas práticas sempre informe os números de acordo com a variável: Caso tenha que multiplicar uma variável doublé por um numero, e supondo que essa variável seja A, bote A * 2.0, utilize do 0 após a virgula para o numero double ser reconhecido. e se for float, utilize de A * 2f, para que o numero float seja reconhecido. Editado Fevereiro 4 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 4 Autor(a) Compartilhar Postado Fevereiro 4 Hoje a noite posto mais exercícios resolvidos. Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 5 Autor(a) Compartilhar Postado Fevereiro 5 (editado) beecrowd | 1003 Simple Sum Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read two integer values, in this case, the variables A and B. After this, calculate the sum between them and assign it to the variable SOMA. Write the value of this variable. Input The input file contains 2 integer numbers. Output Print the message "SOMA" with all the capital letters, with a blank space before and after the equal signal followed by the corresponding value to the sum of A and B. Like all the problems, don't forget to print the end of line, otherwise you will receive "Presentation Error" Resolução: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); a += b; System.out.println("SOMA = " + a); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 5 Autor(a) Compartilhar Postado Fevereiro 5 (editado) beecrowd | 1004 Simple Product Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read two integer values. After this, calculate the product between them and store the result in a variable named PROD. Print the result like the example below. Do not forget to print the end of line after the result, otherwise you will receive “Presentation Error”. Input The input file contains 2 integer numbers. Output Print the message "PROD" and PROD according to the following example, with a blank space before and after the equal signal. Resolução: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a, b; a = sc.nextInt(); b = sc.nextInt(); a *= b; System.out.println("PROD = " + a); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 5 Autor(a) Compartilhar Postado Fevereiro 5 (editado) Exercício de média ponderada, que consiste em multiplicar (X1 * PESO1 + X2 * PESO2) / PESO1 + PESO2; beecrowd | 1005 Average 1 Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read two floating points' values of double precision A and B, corresponding to two student's grades. After this, calculate the student's average, considering that grade A has weight 3.5 and B has weight 7.5. Each grade can be from zero to ten, always with one digit after the decimal point. Don’t forget to print the end of line after the result, otherwise you will receive “Presentation Error”. Don’t forget the space before and after the equal sign. Input The input file contains 2 floating points' values with one digit after the decimal point. Output Print the message "MEDIA"(average in Portuguese) and the student's average according to the following example, with 5 digits after the decimal point and with a blank space before and after the equal signal. 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, media; a = sc.nextDouble(); b = sc.nextDouble(); media = (a * 3.5 + b * 7.5) / 11.0; System.out.printf("MEDIA = %.5f\n", media); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 6 Autor(a) Compartilhar Postado Fevereiro 6 (editado) beecrowd | 1006 Average 2 Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read three values (variables A, B and C), which are the three student's grades. Then, calculate the average, considering that grade A has weight 2, grade B has weight 3 and the grade C has weight 5. Consider that each grade can go from 0 to 10.0, always with one decimal place. Input The input file contains 3 values of floating points (double) with one digit after the decimal point. Output Print the message "MEDIA"(average in Portuguese) and the student's average according to the following example, with a blank space before and after the equal signal. 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, media; a = sc.nextDouble(); b = sc.nextDouble(); c = sc.nextDouble(); media = (a * 2.0 + b * 3.0 + c * 5.0 ) / 10.0; System.out.printf("MEDIA = %.1f\n", media); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 6 Autor(a) Compartilhar Postado Fevereiro 6 (editado) beecrowd | 1007 Difference Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read four integer values named A, B, C and D. Calculate and print the difference of product A and B by the product of C and D (A * B - C * D). Input The input file contains 4 integer values. Output Print DIFERENCA (DIFFERENCE in Portuguese) with all the capital letters, according to the following example, with a blank space before and after the equal signal. 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, d, dif; a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); d = sc.nextInt(); dif = a * b - c * d; System.out.println("DIFERENCA = " + dif); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 6 Autor(a) Compartilhar Postado Fevereiro 6 (editado) beecrowd | 1008 Salary Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Write a program that reads an employee's number, his/her worked hours number in a month and the amount he received per hour. Print the employee's number and salary that he/she will receive at end of the month, with two decimal places. Don’t forget to print the line's end after the result, otherwise you will receive “Presentation Error”. Don’t forget the space before and after the equal signal and after the U$. Input The input file contains 2 integer numbers and 1 value of floating point, representing the number, worked hours amount and the amount the employee receives per worked hour. Output Print the number and the employee's salary, according to the given example, with a blank space before and after the equal signal. 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 n, horas; double salary; n = sc.nextInt(); horas = sc.nextInt(); salary = sc.nextDouble(); System.out.println("NUMBER = " + n); salary *= horas; System.out.printf("SALARY = U$ %.2f\n", salary); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 6 Autor(a) Compartilhar Postado Fevereiro 6 (editado) beecrowd | 1009 Salary with Bonus Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Make a program that reads a seller's name, his/her fixed salary and the sale's total made by himself/herself in the month (in money). Considering that this seller receives 15% over all products sold, write the final salary (total) of this seller at the end of the month , with two decimal places. - Don’t forget to print the line's end after the result, otherwise you will receive “Presentation Error”. - Don’t forget the blank spaces. Input The input file contains a text (employee's first name), and two double precision values, that are the seller's salary and the total value sold by him/her. Output Print the seller's total salary, according to the given example. 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 grat, salario; String nome = sc.next(); grat = sc.nextDouble(); salario = sc.nextDouble(); salario /= 100.0; salario *= 15.0; salario += grat; System.out.printf("TOTAL = R$ %.2f\n", salario); sc.close(); } } Editado Fevereiro 6 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 7 Autor(a) Compartilhar Postado Fevereiro 7 beecrowd | 1010 Simple Calculate Adapted by Neilor Tonin, URI Brazil Timelimit: 1 In this problem, the task is to read a code of a product 1, the number of units of product 1, the price for one unit of product 1, the code of a product 2, the number of units of product 2 and the price for one unit of product 2. After this, calculate and show the amount to be paid. Input The input file contains two lines of data. In each line there will be 3 values: two integers and a floating value with 2 digits after the decimal point. Output The output file must be a message like the following example where "Valor a pagar" means Value to Pay. Remember the space after ":" and after "R$" symbol. The value must be presented with 2 digits after the 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 prod, quant; double valor, total = 0.0; for(int i = 1; i <= 2; i++) { prod = sc.nextInt(); quant = sc.nextInt(); valor = sc.nextDouble(); total += quant * valor; } System.out.printf("VALOR A PAGAR: R$ %.2f\n", total); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 7 Autor(a) Compartilhar Postado Fevereiro 7 beecrowd | 1011 Sphere Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Make a program that calculates and shows the volume of a sphere being provided the value of its radius (R) . The formula to calculate the volume is: (4/3) * pi * R3. Consider (assign) for pi the value 3.14159. Tip: Use (4/3.0) or (4.0/3) in your formula, because some languages (including C++) assume that the division's result between two integers is another integer. 🙂 Input The input contains a value of floating point (double precision). Output The output must be a message "VOLUME" like the following example with a space before and after the equal signal. The value must be presented with 3 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); double raio, sphere, total; raio = sc.nextDouble(); sphere = 4.0 / 3.0 * 3.14159; total = sphere * Math.pow(raio, 3.0); System.out.printf("VOLUME = %.3f\n", total); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 7 Autor(a) Compartilhar Postado Fevereiro 7 beecrowd | 1012 Area Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Make a program that reads three floating point values: A, B and C. Then, calculate and show: a) the area of the rectangled triangle that has base A and height C. b) the area of the radius's circle C. (pi = 3.14159) c) the area of the trapezium which has A and B by base, and C by height. d) the area of the square that has side B. e) the area of the rectangle that has sides A and B. Input The input file contains three double values with one digit after the decimal point. Output The output file must contain 5 lines of data. Each line corresponds to one of the areas described above, always with a corresponding message (in Portuguese) and one space between the two points and the value. The value calculated must be presented with 3 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); double a, b, c; double triangulo, circulo = 3.14159, trapezio, quadrado, retangulo; a = sc.nextDouble(); b = sc.nextDouble(); c = sc.nextDouble(); triangulo = a * c / 2.0; circulo *= Math.pow(c, 2.0); trapezio = (a + b) * c / 2.0; quadrado = Math.pow(b, 2.0); retangulo = a * b; System.out.printf("TRIANGULO: %.3f\n", triangulo); System.out.printf("CIRCULO: %.3f\n", circulo); System.out.printf("TRAPEZIO: %.3f\n", trapezio); System.out.printf("QUADRADO: %.3f\n", quadrado); System.out.printf("RETANGULO: %.3f\n", retangulo); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 7 Autor(a) Compartilhar Postado Fevereiro 7 beecrowd | 1013 The Greatest Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Make a program that reads 3 integer values and present the greatest one followed by the message "eh o maior". Use the following formula: (a + b + abs(a - b)) / 2 Input The input file contains 3 integer values. Output Print the greatest of these three values followed by a space and the message “eh o maior”. 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, abs, maior; a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); abs = (a + b + Math.abs(a - b)) / 2; maior = (abs + c + Math.abs(abs - c)) / 2; System.out.println(maior + " eh o maior"); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 7 Autor(a) Compartilhar Postado Fevereiro 7 beecrowd | 1014 Consumption Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Calculate a car's average consumption being provided the total distance traveled (in Km) and the spent fuel total (in liters). Input The input file contains two values: one integer value X representing the total distance (in Km) and the second one is a floating point number Y representing the spent fuel total, with a digit after the decimal point. Output Present a value that represents the average consumption of a car with 3 digits after the decimal point, followed by the message "km/l". 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 distancia = sc.nextInt(); double consumo = sc.nextDouble(); double km = distancia / consumo; System.out.printf("%.3f km/l\n", km); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 7 Autor(a) Compartilhar Postado Fevereiro 7 beecrowd | 1015 Distance Between Two Points Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read the four values corresponding to the x and y axes of two points in the plane, p1 (x1, y1) and p2 (x2, y2) and calculate the distance between them, showing four decimal places after the comma, according to the formula: Distance = raiz de (x2 - x1)² + (y2 - y1)²; Input The input file contains two lines of data. The first one contains two double values: x1 y1 and the second one also contains two double values with one digit after the decimal point: x2 y2. Output Calculate and print the distance value using the provided formula, with 4 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); double x1, x2, y1, y2; x1 = sc.nextDouble(); y1 = sc.nextDouble(); x2 = sc.nextDouble(); y2 = sc.nextDouble(); double soma = Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2); double raiz = Math.sqrt(soma); System.out.printf("%.4f\n", raiz); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 9 Autor(a) Compartilhar Postado Fevereiro 9 (editado) beecrowd | 1016 Distance Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Two cars (X and Y) leave in the same direction. The car X leaves with a constant speed of 60 km/h and the car Y leaves with a constant speed of 90 km / h. In one hour (60 minutes) the car Y can get a distance of 30 kilometers from the X car, in other words, it can get away one kilometer for each 2 minutes. Read the distance (in km) and calculate how long it takes (in minutes) for the car Y to take this distance in relation to the other car. Input The input file contains 1 integer value. Output Print the necessary time followed by the message "minutos" that means minutes in Portuguese. 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 y = sc.nextInt(); y *= 2; System.out.println(y + " minutos"); sc.close(); } } OBS: EU COSTUMO USAR OS OPERADORES DE ATRIBUIÇÃO CUMULATIVA PARA FAZER CALCULOS, EM VEZ DE Y = Y * 2; EU APENAS UTILIZO O Y *= 2; OPERADORES DE ATRIBUIÇÃO CUMULATIVA: MULTIPLICAR = *= SOMAR = += SUBTRAIR = -= DIVIDIR = /= Editado Fevereiro 9 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 9 Autor(a) Compartilhar Postado Fevereiro 9 beecrowd | 1017 Fuel Spent Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Little John wants to calculate and show the amount of spent fuel liters on a trip, using a car that does 12 Km/L. For this, he would like you to help him through a simple program. To perform the calculation, you have to read spent time (in hours) and the same average speed (km/h). In this way, you can get distance and then, calculate how many liters would be needed. Show the value with three decimal places after the point. Input The input file contains two integers. The first one is the spent time in the trip (in hours). The second one is the average speed during the trip (in Km/h). Output Print how many liters would be needed to do this trip, with three 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 horas, velocidade; horas = sc.nextInt(); velocidade = sc.nextInt(); horas *= velocidade; double consumo = horas / 12.0; System.out.printf("%.3f\n", consumo); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 9 Autor(a) Compartilhar Postado Fevereiro 9 beecrowd | 1018 Banknotes Adapted by Neilor Tonin, URI Brazil Timelimit: 1 In this problem you have to read an integer value and calculate the smallest possible number of banknotes in which the value may be decomposed. The possible banknotes are 100, 50, 20, 10, 5, 2 and 1. Print the read value and the list of banknotes. Input The input file contains an integer value N (0 < N < 1000000). Output Print the read number and the minimum quantity of each necessary banknotes in Portuguese language, as the given example. Do not forget to print the end of line after each line, otherwise you will receive “Presentation Error”. Entrada: 576 Saída: 576 5 nota(s) de R$ 100,00 1 nota(s) de R$ 50,00 1 nota(s) de R$ 20,00 0 nota(s) de R$ 10,00 1 nota(s) de R$ 5,00 0 nota(s) de R$ 2,00 1 nota(s) de R$ 1,00 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 notas, quociente, resto, nota; notas = sc.nextInt(); System.out.println(notas); nota = 100; quociente = notas / 100; System.out.println(quociente + " nota(s) de R$ " + nota + ",00"); resto = notas % 100; nota = 50; quociente = resto / nota; System.out.println(quociente + " nota(s) de R$ " + nota + ",00"); resto %= nota; nota = 20; quociente = resto / nota; System.out.println(quociente + " nota(s) de R$ " + nota + ",00"); resto %= nota; nota = 10; quociente = resto / nota; System.out.println(quociente + " nota(s) de R$ " + nota + ",00"); resto %= nota; nota = 5; quociente = resto / nota; System.out.println(quociente + " nota(s) de R$ " + nota + ",00"); resto %= nota; nota = 2; quociente = resto / nota; System.out.println(quociente + " nota(s) de R$ " + nota + ",00"); resto %= nota; nota = 1; System.out.println(resto + " nota(s) de R$ " + nota + ",00"); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 9 Autor(a) Compartilhar Postado Fevereiro 9 (editado) beecrowd | 1019 Time Conversion Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read an integer value, which is the duration in seconds of a certain event in a factory, and inform it expressed in hours:minutes:seconds. Input The input file contains an integer N. Output Print the read time in the input file (seconds) converted in hours:minutes:seconds like the following example. 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 tempo, horas, resto, minutos, segundos; tempo = sc.nextInt(); horas = tempo / 3600; resto = tempo % 3600; minutos = resto / 60; segundos = resto % 60; System.out.printf("%d:%d:%d\n", horas, minutos, segundos); sc.close(); } } OBS: O OPERADOR MOD( % ) É O RESTO DA DIVISÃO DO DIVIDENDO / DIVISOR, a regra se aplica apenas para os calculos. Editado Fevereiro 9 por Renan Alves Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 10 Autor(a) Compartilhar Postado Fevereiro 10 beecrowd | 1020 Age in Days Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read an integer value corresponding to a person's age (in days) and print it in years, months and days, followed by its respective message “ano(s)”, “mes(es)”, “dia(s)”. Note: only to facilitate the calculation, consider the whole year with 365 days and 30 days every month. In the cases of test there will never be a situation that allows 12 months and some days, like 360, 363 or 364. This is just an exercise for the purpose of testing simple mathematical reasoning. Input The input file contains 1 integer value. Output Print the output, like the following example. 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 dias, anos, meses, dia, resto; dias = sc.nextInt(); anos = dias / 365; resto = dias % 365; meses = resto / 30; dia = resto % 30; System.out.println(anos + " ano(s)"); System.out.println(meses + " mes(es)"); System.out.println(dia + " dia(s)"); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 10 Autor(a) Compartilhar Postado Fevereiro 10 beecrowd | 1035 Selection Test 1 Adapted by Neilor Tonin, URI Brazil Timelimit: 1 Read 4 integer values A, B, C and D. Then if B is greater than C and D is greater than A and if the sum of C and D is greater than the sum of A and B and if C and D were positives values and if A is even, write the message “Valores aceitos” (Accepted values). Otherwise, write the message “Valores nao aceitos” (Values not accepted). Input Four integer numbers A, B, C and D. Output Show the corresponding message after the validation of the values. 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, d; a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); d = sc.nextInt(); if(b > c && d > a && c + d > a + b && c > 0 && d > 0 && a % 2 == 0) { System.out.println("Valores aceitos"); } else { System.out.println("Valores nao aceitos"); } sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Fevereiro 12 Autor(a) Compartilhar Postado Fevereiro 12 beecrowd | 1021 Banknotes and Coins By Neilor Tonin, URI Brazil Timelimit: 1 Read a value of floating point with two decimal places. This represents a monetary value. After this, calculate the smallest possible number of notes and coins on which the value can be decomposed. The considered notes are of 100, 50, 20, 10, 5, 2. The possible coins are of 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Print the message “NOTAS:” followed by the list of notes and the message “MOEDAS:” followed by the list of coins. Input The input file contains a value of floating point N (0 ≤ N ≤ 1000000.00). Output Print the minimum quantity of banknotes and coins necessary to change the initial value, as the given example. 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 notas, moeda, moedas, resto, nota; double valor; valor = sc.nextDouble(); resto = (int) (valor * 100); System.out.println("NOTAS:"); nota = 100; notas = resto / (nota * 100); System.out.printf(notas + " nota(s) de R$ %d.00\n", nota); resto %= (nota * 100); nota = 50; notas = resto / (nota * 100); System.out.printf(notas + " nota(s) de R$ %d.00\n", nota); resto %= (nota * 100); nota = 20; notas = resto / (nota * 100); System.out.printf(notas + " nota(s) de R$ %d.00\n", nota); resto %= (nota * 100); nota = 10; notas = resto / (nota * 100); System.out.printf(notas + " nota(s) de R$ %d.00\n", nota); resto %= (nota * 100); nota = 5; notas = resto / (nota * 100); System.out.printf(notas + " nota(s) de R$ %d.00\n", nota); resto %= (nota * 100); nota = 2; notas = resto / (nota * 100); System.out.printf(notas + " nota(s) de R$ %d.00\n", nota); resto %= (nota * 100); System.out.println("MOEDAS:"); moeda = 100; moedas = resto / moeda; System.out.println(moedas + " moeda(s) de R$ 1.00"); resto %= moeda; moeda = 50; moedas = resto / moeda; System.out.println(moedas + " moeda(s) de R$ 0.50"); resto %= moeda; moeda = 25; moedas = resto / moeda; System.out.println(moedas + " moeda(s) de R$ 0.25"); resto %= moeda; moeda = 10; moedas = resto / moeda; System.out.println(moedas + " moeda(s) de R$ 0.10"); resto %= moeda; moeda = 5; moedas = resto / moeda; System.out.println(moedas + " moeda(s) de R$ 0.05"); resto %= moeda; System.out.println(resto + " moeda(s) de R$ 0.01"); sc.close(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Postagens Recomendadas
Crie uma conta ou entre para comentar 😀
Você precisa ser um membro para deixar um comentário.
Crie a sua conta
Participe da nossa comunidade, crie sua conta.
Criar minha conta agoraÉ bem rápido!
Entrar
Você já tem uma conta?
Entrar agoraFaça o login agora.