| | |
Several errors in java
![]() |
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
Solved Threads: 0
class t{
Somebody please help me with one very simple program in java. I'm new to java, so I can't understand what all this errors about. Please help me fix this program.
It gives three errors:
illegal start of type
swith (s)
orphaned case
case 'Y':
<identifier> expected
switch (s);
__________________________
Somebody please help me with one very simple program in java. I'm new to java, so I can't understand what all this errors about. Please help me fix this program.
It gives three errors:
illegal start of type
swith (s)
orphaned case
case 'Y':
<identifier> expected
switch (s);
__________________________
class t {
char s = 'Y';
switch (s);
{
case 'Y':
System.out.println("Yes");
break;
case 'N':
System.out.println("No");
break;
default:
System.out.println("Default");
break;
}
} Note: before you read this, i'm giving out some explanations based on what i saw from your questions. But these explanations are nowhere close to all the things that you'll be able to do. I'd recommend you to look into a book for a wider approach to Java, and algorithms. I don't know what "level" are you in programming, so i explained it to you as if you were a beginner, so i hope you don't die of boredom with my explanations.
It's not a matter of a specific method, as it is a matter of you creating your own methods. When creating a class you're outlining something. It is like answering what? and how?. I think of it this: i you were to build a hardcore metal grinding guitar, you'd first must outline the shape, size, weight, but also the technical specifications (pickups, bridge, fretboard) and with them . You'd end up whit a piece of paper with what is and what can your guitar do but not with a guitar.
So you have what the guitar is (shape, size, ...) and how you're going to achieve the metal sound (ebony fretboard with EMG humbucking pickups). Back to the class, you'll be outlining an object with atributes (what) and methods (how). So, if you wish to create an object you have to define attributes and methods.
Again, i think you sould get your hands on some book about java.
take care
It's not a matter of a specific method, as it is a matter of you creating your own methods. When creating a class you're outlining something. It is like answering what? and how?. I think of it this: i you were to build a hardcore metal grinding guitar, you'd first must outline the shape, size, weight, but also the technical specifications (pickups, bridge, fretboard) and with them . You'd end up whit a piece of paper with what is and what can your guitar do but not with a guitar.
So you have what the guitar is (shape, size, ...) and how you're going to achieve the metal sound (ebony fretboard with EMG humbucking pickups). Back to the class, you'll be outlining an object with atributes (what) and methods (how). So, if you wish to create an object you have to define attributes and methods.
Again, i think you sould get your hands on some book about java.
take care
Exit light, enter night
JOSH
JOSH
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
Even if you fix the switch statement, executable code like switch statements need to be located inside of a function/method/constructor of some type. Your switch statement is just floating around inside your class, so even if you fix the switch statement, it's still not going to work.
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
Try looking at http://java.sun.com/docs/books/tutorial/. I can't really tell you if they are really good tutorials (as I learned in high school/university), but it should give you an idea of Java syntax, and get you started.
•
•
Join Date: Jun 2009
Posts: 28
Reputation:
Solved Threads: 3
This should work for you.
java Syntax (Toggle Plain Text)
class t { public static void main (String [] args){ //do stuff char s = 'Y'; displayStuff(s); }//end main public static void displayStuff(char s){ switch (s){ case 'Y':System.out.println("Yes"); break; case 'N': System.out.println("No"); break; default: System.out.println("Default"); break; } } }
Last edited by PopeJareth; Jul 30th, 2009 at 11:48 am.
![]() |
Similar Threads
- Errors in Java (Java)
- getting errors in java for an assignment (Java)
- class recieving compiler errors in java (Java)
- errors regarding java code in jsp page. help me please (JSP)
- Beginner using Java... Having trouble with javac and creation of .class files. (Java)
- Errors in Java using netbeans (Java)
Other Threads in the Java Forum
- Previous Thread: How to clear screen in java?
- Next Thread: BubbleSort Problem...
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






