Java program to accept an integer from user and print it

Object Oriented ProgrammingJava Programming Java8

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
raja
Published on 26-Apr-2018 12:51:25
Advertisements