In this tutorial, we will discuss a simple concept of Write a Java program to print an integer
In this post, we are going to learn about how to print an integer number entered by the user in Java programming language
The value is stored in a variable num using Scanner class(System.in) and it is displayed on the screen using System.out.print() statements.
Program 1
import java.util.Scanner; class PrintInt{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for receives input //from the user - input from keyboard System.out.print("Enter the number: "); int num=scan.nextInt(); //reads the integer value from the user //input from keyword System.out.print("You entered : "+num); } }
When the above code is executed, it produces the following results
Enter the number:999 you entered : 999
In the Java program, the user can enter a value using the scanner class and that value is stored in a variable named num. Then prints that value using a display statement in the Java language
In this program, System.out.print() provides a piece of information to the user for entering an integer value
System.out.print("Enter the number: ");
Then, it reads an integer value from the user and stores in variable num
int num=scan.nextInt();
Finally, the value stored in the variable num is displayed on the screen by using System.out.print() method
System.out.print("You entered : "+num);
Recommended post
Write a C program to print an integer
Write a Cpp program to print an integer
Write a Python program to print an integer
write a Java program print characters of a string
write a C++ program print characters of a string
write a C program print characters of a string
write a Java program to print characters of a string
Suggested for you
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…