Created
March 7, 2022 12:21
-
-
Save connor-davis/bf1db189236ebdb1c268f3875b6c971c to your computer and use it in GitHub Desktop.
InputOne Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This Java source file was generated by the Gradle 'init' task. | |
*/ | |
package inputone; | |
import java.io.IOException; | |
import java.util.Scanner; | |
public class InputOne { | |
public static void main(String[] args) { | |
// program to take values from the user | |
// declare the variables | |
String firstName; | |
String lastName; | |
try { | |
// Create a Scanner object | |
try (Scanner scanner = new Scanner(System.in)) { | |
// Request for the firstName | |
System.out.println("Enter your first name:"); | |
System.out.write("> ".getBytes()); | |
firstName = scanner.next(); | |
// Request for the lastName | |
System.out.println("Enter your last name:"); | |
System.out.write("> ".getBytes()); | |
lastName = scanner.next(); | |
} | |
// Say hello to the firstName lastName | |
System.out.println("Hello, " + firstName + " " + lastName); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment