Java program to accept an integer from user and print it


Scanner class of the util package class is used to read data from user The nextInt() method of this class reads an integer from the user.

Program

import java.util.Scanner;
public class PrintInteger {
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter an integer:");
      int num = sc.nextInt();
      System.out.print("Given integer is :: "+num);
   }
}

Output

Enter an integer:
123
Given integer is :: 123

Updated on: 13-Mar-2020

743 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements