The given task is to take an integer as input from the user and print that integer in Java language.
In below program, the syntax and procedures to take the integer as input from the user is shown in Java language.
Steps:
Syntax:
variableOfIntType = ScannerObject.nextInt(); where variableOfIntType is the variable in which the input value is to be stored. And ScannerObject is the beforehand created object of the Scanner class.
Syntax:
System.out.println(variableOfXType);
Program:
// Java program to take an integer // as input and print it import java.io.*; import java.util.Scanner; class GFG { public static void main(String[] args) { // Declare the variables int num; // Input the integer System.out.println("Enter the integer: "); // Create Scanner object Scanner s = new Scanner(System.in); // Read the next integer from the screen num = s.nextInt(); // Display the integer System.out.println("Entered integer is: " + num); } }
Output:
Enter the integer: 10 Entered integer is: 10
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.