Write a Java Program to Print an Integer Entered by the User

January 22, 2023 0 Comments

In this tutorial learn how you can print a program to print an integer entered by the user in java. Simply we will use the Scanner class of java from package java.util using code “import java.util.Scanner;”.

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

Write a Program to Print an Integer Entered by the User

Here is the code to print a program to print an integer entered by the user in Java programming.

//Write a program to print an integer entered by the user.
import java.util.Scanner;

public class Integer {
    public static void main(String[] args) {
        int Number;
        Scanner data = new Scanner(System.in);
        System.out.println("Enter any number, we will show you magic:");
        Number = data.nextInt();
        System.out.println("You have pressed number " + Number + ".");
        data.close();

    }
}

Test Live At Jdoodle

Conclusion

This is how you can display an integer entered by the user in java programming. Comment below if you like our tutorial.

Leave a comment

Gallery