Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions