Question
Questions : 1. Why is this saying Display() is unreachable? 2. How do I get it to continuously repeat itself until i exit out with
Questions :
1. Why is this saying Display() is unreachable?
2. How do I get it to continuously repeat itself until i exit out with 2?
3. and how do i add 2 to make it exit. Thank you.
package peopleinclass; import java.util.Scanner;
public class PeopleinClass { 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(); 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