Question: Java Printing numbers from 1 to n Complete the following program in order to print to the console the numbers from 1 to n, separating

Java

Printing numbers from 1 to n

Complete the following program in order to print to the console the numbers from 1 to n, separating each of them by using a single white space. Assume that n is an integer number, greater or equal than 1, that is given by the user through keyboard input (please note that this part of the code is already provided).

 

1

import java.util.Scanner;

2

 

3

public class Lab3 {

4

 public static void main(String[] args){

5

 // Create a scanner to read from keyboard

6

 Scanner kbd = new Scanner (System.in);

7

 

8

 // Prompt user for typing a numeric input

9

 System.out.print("Enter value of n: ");

10

 

11

 //Stores the integer value from keyboard in the variable n

12

 int n = kbd.nextInt();

13

 

14

 //YOU MUST NOT WRITE ANY CODE ABOVE THIS LINE

15

 

16

 // Type your code here:

17

 

18

 

19

 

20

 //YOU MUST NOT WRITE ANY CODE BELOW THIS LINE

21

 }

22

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!