
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
More Posts related to Java,
- Java equals method - Tutorial
- Unbound classpath container: JRE System Library [JavaSE-1.7]
- Spring Boot: @RequestBody not applicable to method
- Java 8: Steam map with Code Examples
- Java Program: Random Number Generator
- Java java.time.Clock class code examples [Java Date Time API]
- Fix: type argument is not within bounds of type-variable T
- [Fix] java.net.MalformedURLException: unknown protocol
- Java 7 addSuppression() and getSuppression() Exception Handling
- Convert Java Array to ArrayList Code Example
- How to Word-Warp Console logs in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Remove Trailing zeros BigDecimal Java
- CRUD operations in Spring Boot + JDBC
- [Java Threads] Should we extend Thread Class or implement Runnable interface
- Json Serialization and Deserialization using Java Jackson
- Create simple struts2 project using maven commands
- How to install Java OpenJDK 11 on Alpine Linux
- Unsupported major.minor version 52.0 in java
- Error: Can not find the tag library descriptor for
- Java: Convert String to Binary
- How to run Java Unit Test cases with Apache Maven?
- Java: Testing Private Methods in JUnit using reflection API Example
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java Join Strings with Comma Separator
More Posts:
- How to find version of Cargo in Rust - Rust
- Examples: Convert String to int in JavaScript - JavaScript
- How to remove quotes from a String in Python - Python
- Display full website URL/address in Safari macOS Browser - MacOS
- SharePoint workflow Canceled - Coercion Failed: Unable to transform the input lookup data into the requested type - SharePoint
- What does apt-get update command does? - Linux
- Python Comments Multiple Lines - Python
- How to Send or Publish SNS Message using AWS CLI - AWS