Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package exercicios_for;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. int x = 0;
  10.  
  11. while(true) {
  12.  
  13. System.out.print("Digite um número de 0 a 100: ");
  14. x = sc.nextInt();
  15.  
  16. if(x >= 0 && x <= 100)
  17. {
  18. System.out.printf("Os números primos de 0 a %d são:\n", x);
  19. for (int i=0 ; i<=x ; i++) {
  20. if (i % 2 !=0)
  21. System.out.println(i);
  22. }
  23.  
  24.  
  25. System.exit(0);
  26.  
  27. }
  28. else
  29. {
  30. System.out.println("Número fora do intervalo.");
  31. }
  32.  
  33.  
  34. }
  35.  
  36. }
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement