knugi

Untitled

Jun 30th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package zajęcia2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Zad1 {
  6. public static void main(String[] args){
  7. System.out.println("Podaj liczbę całkowitą dodatnią.");
  8. Scanner wej = new Scanner(System.in);
  9. int liczba;
  10. while(true){
  11. if(wej.hasNextInt()){
  12. liczba = wej.nextInt();
  13. if(liczba>0){
  14. break;
  15. }
  16. System.out.println("Liczba musi być dodatnia!");
  17. continue;
  18. }
  19. System.out.println("To musi być liczba!");
  20. wej.next();
  21. continue;
  22. }
  23. for(int i=1;i<liczba+1;i++){
  24. //System.out.println(i);
  25. if(!(i%2==0)){
  26. System.out.print(i+", ");
  27. }
  28. }
  29. System.out.println("Koniec programu.");
  30.  
  31. wej.close();
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment