[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?

Code:
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);


    }
}
Output:

% 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


Top Hashtags:

Advertisements

Advertisements




Advertisements