Write a for loop that prints: 1 2 ... userNum
Ex: userNum = 4 prints:
1 2 3 4
import java.util.Scanner;
public class ForLoops {
public static void main (String [] args) {
int userNum;
int i;
Scanner input = new Scanner(System.in);
userNum = input.nextInt();
for (/* Your code goes here */) {
System.out.print(i + " ");
}
}
}
Need to fill out the "for" solved in JAVA
import java.util.Scanner; public class ForLoops { public static void main(String[] args) { int userNum; int i; Scanner input = new Scanner(System.in); userNum = input.nextInt(); for (i = 1; i <= userNum; i++) { System.out.print(i + " "); } } }
Get Answers For Free
Most questions answered within 1 hours.