Java Programs

Java Practice

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*/
		System.out.println("Value of a:" +a); 


Enter value of a :120 
Value of a:120 

Java Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.