Renan Alves Postado Março 8 Autor(a) Compartilhar Postado Março 8 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(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Março 10 Autor(a) Compartilhar Postado Março 10 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(); } } Link to comment Compartilhe em outros sites Outras opções de compartilhamento...
Renan Alves Postado Março 10 Autor(a) Compartilhar Postado Março 10 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(); } } 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.