Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Three business partners are forming a company whose name will be of the form \"N

ID: 3549751 • Letter: T

Question

Three business partners are forming a company whose name will be of the form "Name 1, 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 been declared and use them in your code. Assume also that stdin is a variable that reference 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.

Explanation / Answer

import java.util.Scanner;

public class business {

public static void main(String args[]){

Scanner stdin = new Scanner(System.in);

System.out.println("Enter Names");

String Name1 = stdin.nextLine();

String Name2 = stdin.nextLine();

String Name3 = stdin.nextLine();

System.out.println(Name1 +", " + Name2 + " and " + Name3);

System.out.println(Name1 + ", " + Name3 + " and " + Name2);

System.out.println(Name2 + ", " + Name1 + " and " + Name3);

System.out.println(Name2 + ", " + Name3 + " and " + Name1);

System.out.println(Name3 + ", " + Name1 + " and " + Name2);

System.out.println(Name3 + ", " + Name2 + " and " + Name1);


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote