Write a for loop that prints 1 2 userNum Print a space afte

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;

Solution

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

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site