#Should I just email my TA?
54 messages · Page 1 of 1 (latest)
@supple herald it’s because you’re using nextInt and that doesn’t clear the new line character you added when pressing enter. So the next time you try to get user input, it just fills that with the leftover new line
Read about it here
but when i add input.nextLine(); under the nextInt() line i get an actual error
I don't think that was the real problem, but you're still supposed to tell what is the "actual error". Normally you wouldn't have an error when doing that
when i added it it was asking me to initialize input as a variable which doesn't make sense
When I said "tell" I meant "show", and you really shouldn't need to be told something so obvious
No that part is non apologizing worthy. We've all been there
Yeah. If you ask me the error report is unhelpful
Though it looks like, from the expectations, you're supposed to be able to handle incorrect user input
it just tells me it failed to compile
Failed to compile? Dang
well with incorrect user input i made it so that the program ends
because thats what my lab asked me to do
It's a problem when it compiles fine on your computer and not on the grading lab
yeah, i think im just going to email my Ta
We could try and guess when seeing your entire file, but honestly...
public class Lab11A {
public static void menu(){
System.out.println("Menu");
System.out.println("0) Hello World");
System.out.println("1) Goodbye Moon");
System.out.println("2) Walking on Sunshine");
System.out.println();
System.out.print("What would you like to do: ");
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int choice;
String response;
do{
menu();
choice = scan.nextInt();
scan.nextLine();
switch(choice){
case 0 -> {
System.out.println();
System.out.println("Hello!");
System.out.println();
}
case 1 -> {
System.out.println();
System.out.println("Ok, bye.");
System.out.println();
}
case 2 -> {
System.out.println();
System.out.println("WHOA!");
System.out.println();
}
}
System.out.print("Type YES to rerun. ");
response = scan.nextLine();
System.out.println();
}while(response.equalsIgnoreCase("yes"));
System.out.println("Program Ends");
}
}```
i mean
idk i feel like i did everything right
It's not impossible that the lab would not like -> styled switch
Have you seen it work before?
switch that uses the -> syntax
older switch syntax uses case STUFF: and a break later
idk how the autograder works this is my first time using it
Doesn't cost much to try the older syntax first
but my lab11B program is quite similar and the autograder was able to run it
similar okay, but does it do a switch like that?
well originally u just used a while loop
i got the same error
so i switch it to a do while
and it still gives me the error
and yes
it does do a switch
like that
It would be interesting to compare the program that works and the one that doesn't, but yeah, I guess help from the TA will be needed