Write a for loop that prints: 1 2 .. userNum. Print a space after each number, i
ID: 3923758 • Letter: W
Question
Write a for loop that prints: 1 2 .. userNum. Print a space after each number, including after the last number. Ex: userNum = 4 prints:
Challenge Activity lge 4.5.2: For loop: Print 1 to N Write a for loop that prints: 1 2.. userNum. Print a space after each number, including after the last number. Ex: userNum 4 prints: 1 23 4 1 import java.util.scanner; 2 3 public class CountToNum f 4public static void main (String [] args) int userNum- int i -e; 6 7 8 9 10 userNum 4; 12 3 14 15 16 Your solution goes here System.out.println(""); return;Explanation / Answer
CountToNum.java
public class CountToNum {
public static void main(String arg[]){
int userNum = 0;
int i=0;
userNum = 4;
for(i=1; i<=userNum; i++){
System.out.print(i+ " ");
}
return ;
}
}
Output:
1 2 3 4
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.