Question #3523

4) Write a program to print n umbers and enter a number where you want to break the program

Expert's answer

import java.util.Scanner;




public class Main {




public static void main(String[] args) {




int n;

Scanner in = new Scanner(System.in);

System.out.print("Enter a number where you want to break the program: ");

n = in.nextInt();

if(n > 0){

for(int i = 1; i < n+1; i++){

System.out.println(i);

}

}

else

System.out.println("ERROR");

}




}
LATEST TUTORIALS
APPROVED BY CLIENTS