Happy Thanksgiving, everyone!
I'm running into an issue with a homework problem and could use some guidance....I've included my code and the question for further review and assistance...
Three business partners are forming a company whose name will be of the form "Name1, Name2 and Name3". However, they can't agree whose name should be first, second or last. Help them out by writing code that reads in their three names and prints each possible combination exactly once, on a line by itself (that is, each possible combination is terminated with a newline character). Assume that name1, name2 and name3 have already been declared and use them in your code. Assume also that stdin is a variable that references a Scanner object associated with standard input. For example, if your code read in "Larry", "Curly" and "Moe" it would print out "Larry, Curly and Moe", "Curly, Larry and Moe", etc., each on a separate line.
Here's my code I've written on NetBeans:
import java.util.Scanner;
public class ThreePartners {
public static void main(
String [] args) {
Scanner stdin = new Scanner(System.in);
System.out.println("Enter three names:");
String name1 = stdin.next();
String name2 = stdin.next();
String name3 = stdin.next();
System.out.print(name1 + ", " + name2 + " and " + name3 + "\n");
System.out.print(name2 + ", " + name3 + " and " + name1 + "\n");
System.out.print(name3 + ", " + name1 + " and " + name2);
}
}
And here's my result....although it says it's successful on NetBeans, I'm not quite sure it's right even though it's "successful", plus MyProgrammingLab through Pearson and Dr. Liang's Intro to
Java 9th Ed., Comprehensive isn't happy with the code, either... :/
run:
Enter three names:
Larry
Curly
Moe
Larry, Curly and Moe
Curly, Moe and Larry
Moe, Larry and CurlyBUILD SUCCESSFUL (total time: 13 seconds)
Thanks again for the assistance....this is much harder than I have anticipated, yet I'm having the time of my life and really enjoying this!
Eddie Gerlach
Greenhorn