[Program] How to read three different values using Scanner in Java

Java Scanner Program to read three inputs
Java Scanner Program to read three inputs
Program: How to read three different values using Scanner in Java?

import java.util.Scanner;

 * Program to read three integers
 * as input using Scanner Class
 * Code2care.org Java Programs
 * Update: 19 March 2022
public class ScannerReadExample {

    public static void main(String... args) {

        Scanner scannerObject = new Scanner(System.in);

        System.out.print("Enter value of first Integer: ");
        int firstInteger=scannerObject.nextInt();

        System.out.print("Enter value of second Integer: ");
        int secondInteger=scannerObject.nextInt();

        System.out.print("Enter value of third Integer: ");
        int thirdInteger=scannerObject.nextInt();

        System.out.println("---------- Output -----------");
        System.out.println("Entered 1st Integer Value: " + firstInteger);
        System.out.println("Entered 2nd Integer Value: " + secondInteger);
        System.out.println("Entered 3rd Integer Value: " + thirdInteger);


% javac ScannerReadExample.java

% java ScannerReadExample
Enter value of first Integer: 5
Enter value of second Integer: 10
Enter value of third Integer: 15

---------- Output -----------
Entered 1st Integer Value: 5
Entered 2nd Integer Value: 10
Entered 3rd Integer Value: 15

Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.