Computing.Net > Forums > Programming > Using the switch statement in java

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Using the switch statement in java

Reply to Message Icon

Name: TANDO
Date: March 1, 2005 at 13:03:50 Pacific
OS: WINDOWS XP
CPU/Ram: PENTIUM 4
Comment:

When I compile the code below I get this error message : " illegal start of expression "
The code is :public class MySwitch
{
public static void main (String[] args)
{
String MyString1="Tando";
String MyString2="Sibanda";
int MyInt1=-5;
int MyInt2=-9;

System.out.println(MyString1); // Output is : Tando
System.out.println(MyString2); // Sibanda
System.out.println(MyInt1); // -5
System.out.println(MyInt2); // -9

MyInt2= MyInt2+5; // Adding (-9)+(5)
System.out.println(MyInt2); // Output is 4

int i=1;
if (MyInt1==Myint2) ;


=(MyInt1==MyInt2);
switch(i)


{
case 1: System.out.println(MyInt1);break;
case 2: System.out.println(MyInt2);break;

}



}
}

HOW CAN I SOLVE THIS PROBLEM?



Sponsored Link
Ads by Google

Response Number 1
Name: JordanMc31
Date: March 1, 2005 at 19:49:57 Pacific
Reply:

int i=1;
if (MyInt1==Myint2) ;

Need to capitalize MyInt2


0

Response Number 2
Name: Dr. Nick
Date: March 1, 2005 at 23:37:05 Pacific
Reply:

Jordan is right, but it also looks like your code was botched by the forum.

Try running your code through my little converter, then post it. Let me know if it doesn't work quite right.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch script Help Assigning random to array...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Using the switch statement in java

How to use Switch statement in vb www.computing.net/answers/programming/how-to-use-switch-statement-in-vb/6687.html

Switch statement in vb6..? www.computing.net/answers/programming/switch-statement-in-vb6/9080.html

java switch statement problem www.computing.net/answers/programming/java-switch-statement-problem/13602.html