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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started