Q:

How to read and print an integer value in Java?

belongs to collection: Java Basic Programs

0

Take an integer as input and print on the output screen.

Here, we will learn how to take an integer input from user and print on the screen, to take an integer value's input - we use Scanner class, for this we have to include java.util.* package in our Java program.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

import java.util.*; 
 
class j3
{	
	public static void main(String args[]) 
	{ 
		int a; 

		//declare object of Scanner Class
		Scanner buf=new Scanner(System.in); 
		
		System.out.print("Enter value of a :"); 
		/*nextInt() method of Scanner class*/
		a=buf.nextInt(); 
		
		System.out.println("Value of a:" +a); 
	} 
}

Output

Enter value of a :120 
Value of a:120 

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to find sum and average of two intege... >>
<< How to print different type of values in Java?...