
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Print an Integer
In this article, we will understand how to print an integer in Java. It uses the int data type. The int data type is a 32-bit signed two's complement integer. The Minimum value is 2,147,483,648 (-2^31) and the Maximum 2,147,483,647(inclusive) (2^31 -1). Integer is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0.
Input
Suppose our input is
Enter an integer: 45
Output
The desired output would be
The integer is: 45
Algorithm
Step 1- START Step 2- Prompt the user to enter an integer value/ define the integer value in a variable Step 3- Read the value Step 4- Display it on the console Step 5- STOP
Example 1
Here, the input is being entered by the user based on a prompt. You can try this example live in our coding ground tool .
import java.util.Scanner; public class PrintInteger { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.println("Required packages have been imported"); System.out.print("A reader object has been defined "); System.out.print("Enter an integer: "); int number = reader.nextInt(); System.out.print("The nextInt method is used to read the integer value "); System.out.println("The integer is: " + number); } }
Output
Required packages have been imported A reader object has been defined Enter an integer: 45 The nextInt method is used to read the integer value The integer is: 45
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class PrintInteger { public static void main(String[] args) { int number; number = 45; System.out.print("The value for integer has been defined "); System.out.println("The integer value is: " + number); } }
Output
The value for integer has been defined The integer is: 45
- Related Articles
- Kotlin Program to Print an Integer
- Java program to accept an integer from user and print it
- How to Print an Integer in Swift Program?
- Java Program to Print a Square Pattern for given integer
- C++ Program to print unique integer pairs
- Java Program to convert an integer into binary
- Java program to print all distinct elements of a given integer array in Java
- How to Print an Integer in Golang?
- Java Program to Count set bits in an integer
- 8085 program to print the table of input integer
- 8086 program to print the table of input integer
- Java Program to extend the size of an Integer array
- Java Program to Count Number of Digits in an Integer
- How to Read and Print an Integer value in C++
- Java Program to convert integer to boolean

Advertisements