Basic

Write a Java program to print an integer

Write a Java program to print an integer

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

 

Java program to print an integer

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 scanner class and that value stored in a variable named as num. then prints that value using display statements in 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

 

Suggested for you

Datatype and variable in Java

Operator in Java

class and main method in Java

input output function in the C language
Write a C program to print an integer
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago