Question: Question : How do I display all names at the end when I am done entering in the students name, and its time to exit.

Question : How do I display all names at the end when I am done entering in the students name, and its time to exit.

Thank you.

package sidebyside;

import java.util.Scanner;

public class SideBySide { static Scanner get = new Scanner(System.in); static String yourName; static int studentNames = 0; static int answer = 1;

public static void main(String[] args) {

getNames();

while (true) { if (answer == 1) { System.out.println("Would you like to add another student? 1 for yes 2 for no "); answer = get.nextInt(); get.nextLine(); // we need to stop it when user enters 2 if (answer == 2) break; System.out.println("Please enter another students name: "); yourName = get.nextLine();

}

}

Display();

}

public static String getNames() {

System.out.println("Please enter your students name: "); yourName = get.nextLine();

return yourName; }

public static void Display() {

System.out.println("Below are the students in the class: "); System.out.println(studentNames);

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!