Java Program to Print Integers

Java program to print integers. In the Java program, print the value obtained from the user. This is the first step in learning,  how to print a number in the Java programming language. For beginners, these are the simple java program to print and how to run them in java.

system.out.println in Java

The print() method is employed. In Java, the System. out. println() function writes the value supplied as a parameter to it on the console screen and moves the cursor to the next line. After that, the entered integers are saved in the integer variable number. The compiler will issue an InputMismatchException if you enter any character that is not an integer. 

Finally, the function println() is used to print the number on the standard output ( System. out ) – computer screen. print(): In Java, the print() function is used to display text on the console. This method accepts this text as a parameter in the form of a String. This method outputs the text to the console while keeping the cursor at the conclusion of the text.

Integer in Java

In Java, an int is a primitive data type, but an Integer is a Wrapper class. Because int is a basic data type, it has little flexibility. Only the binary value of an integer may be stored in it. Integer variables, like any other reference type, store references to Integer objects.

Scanner in Java Program

The scanner is a class in the Java util package that is used to get the input of primitive kinds such as int, double, and strings. It’s the simplest way to read input in a Java program, but it’s not particularly efficient if you’re looking for an input method for situations where time is a factor, such as competitive programming.

It implies importing all of Java’s classes and interfaces. Make the utilities in the util package available for usage within the current class or interface. This is a shortcut wildcard annotation for importing all classes included within a certain package. This will not import the classes from the java sub-packages.

Package in Java

A package is a namespace that groups together a collection of related classes and interfaces. Because software built in the Java programming language might have hundreds or thousands of distinct classes, it makes it logical to group similar classes and interfaces into packages to keep things organized. In Java, a package is used to bring together similar classes. Consider it a folder in a file system. Packages help us avoid name clashes and produce more maintainable code.

import java.util.Scanner;
public class Main
public static void main(String args[])
int number;
Scanner scan = new Scanner(;
System.out.print("Enter the number ");
number = scan.nextInt();
System.out.print("Entered number " +number);


Enter the number  456

Entered number 456