Skip to content

Instantly share code, notes, and snippets.

@connor-davis
Created March 7, 2022 12:21
Show Gist options
  • Save connor-davis/bf1db189236ebdb1c268f3875b6c971c to your computer and use it in GitHub Desktop.
Save connor-davis/bf1db189236ebdb1c268f3875b6c971c to your computer and use it in GitHub Desktop.
InputOne Code
/*
* 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