Write a statement that reads a users input integer into the

Write a statement that reads a user\'s input integer into the defined variable, and a second statement that prints the integer. Do not end with a newline.

import java.util.Scanner;

public class InputExample {

public static void main(String [] args) {

Scanner scnr = new Scanner(System.in);

int userNum = 0;

YOUR SOLUTION GOES HERE

return;

}

}

Solution

import java.util.Scanner;

public class InputExample {

public static void main(String [] args) {

Scanner scnr = new Scanner(System.in);

int userNum = 0;

userNum=scnr.nextInt(); //this statement uses scnr which is an object of Scanner clasa to call the method
//nextInt which scan the next integer and stores it in userNum

System.out.print(\"user input is : \"+userNum); //this prints the number and since print is used it waits in same line

return;

}

}

Write a statement that reads a user\'s input integer into the defined variable, and a second statement that prints the integer. Do not end with a newline. impor

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site