Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zajęcia2;
- import java.util.Scanner;
- public class Zad1 {
- public static void main(String[] args){
- System.out.println("Podaj liczbę całkowitą dodatnią.");
- Scanner wej = new Scanner(System.in);
- int liczba;
- while(true){
- if(wej.hasNextInt()){
- liczba = wej.nextInt();
- if(liczba>0){
- break;
- }
- System.out.println("Liczba musi być dodatnia!");
- continue;
- }
- System.out.println("To musi być liczba!");
- wej.next();
- continue;
- }
- for(int i=1;i<liczba+1;i++){
- //System.out.println(i);
- if(!(i%2==0)){
- System.out.print(i+", ");
- }
- }
- System.out.println("Koniec programu.");
- wej.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment