samedi 31 janvier 2015

Im having trouble with using mutliple parts to an if/else statement.

This is a pearson myprogramming lab exercise. Not exactly what the error message is referring to. I tried flipping the choice = B and choice = T sections and what occurred was the error message just then said that there was an issue with the choice = B else missing if.





CTest.java:17: error: 'else' without 'if'
else if(choice = T)
^

1 import java.util.Scanner;
2
3 class CTest {
4 public static void main(String [] args) {
5 Scanner stdin = new Scanner(System.in);
6
7 int age = 0;
8 String choice = null;
9
10 System.out.print("Enter your menu selection: ");
11 choice = stdin.nextString();
12 if(choice = S);
13 {
14 if(age <= 21)
15 System.out.println("Vegetable Juice");
16 else System.out.println("Cabernet");
17 }
18 else if(choice = T)
19 {
20 if(age <= 21)
21 System.out.println("Cranberry Juice");
22 else System.out.println("Chardonnay");
23 }
24 else if(choice = B)
25 {
26 if(age <= 21)
27 System.out.println("soda");
28 else System.out.println("IPA");
29 }
30 else
31 {
32 System.out.println("invalid menu selection");
33 }
34
35
36 }
37 }



Aucun commentaire:

Enregistrer un commentaire