/
HelloGoodbye.java
38 lines (36 loc) · 1.28 KB
/
HelloGoodbye.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/****************************************************************************************************
* Compilation: javac HelloGoodby.java name1 name2
* Execution: java HelloGoodbyTest
*
* Author: Tara Fife
*
* Input: Two names
* Output: Says hello to the two names in order, and then goodby to the two names in reverse order
*
* ~/Desktop/hello> javac HelloGoodbye.java
*
* ~/Desktop/hello> java HelloGoodbye Kevin Bob
* Hello Kevin and Bob.
* Goodbye Bob and Kevin.
*
* ~/Desktop/hello> java HelloGoodbye Alejandra Bahati
* Hello Alejandra and Bahati.
* Goodbye Bahati and Alejandra.
*
*
***************************************************************************************************/
public class HelloGoodbye
{
public static void main(String[] args) {
if (args.length > 0) {
// Use the provided name
String name1 = args[0];
String name2 = args[1];
System.out.println("Hello " + name1 + " and " + name2 + ".");
System.out.println("Goodbye " + name2 + " and " + name1 + ".");
} else {
// If no name provided, prompt the user to enter a name
System.out.println("Please provide names as a command-line argument.");
}
}
}