ADVERTISEMENT
ADVERTISEMENT

How to read and print an integer value in Java?

Through this program, we will learn how to read (input) an integer number from user and print the input value on the output screen?

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.

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 

Java Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.