Results 1 to 12 of 12
Thread: The Switch Statement
- 04-10-2012, 04:01 PM #1
The Switch Statement
I have been stuck on this problem for 30 minutes:
" Write the definition of a method printAttitude , which has an int parameter and returns nothing. The method prints a message to standard output depending on the value of its parameter.
- If the parameter equals 1 , the method prints disagree
- If the parameter equals 2 , the method prints no opinion
- If the parameter equals 3 , the method prints agree
- In the case of other values, the method does nothing.
Each message is printed on a line by itself."
This is the code that I have assembled:
Every time I submit it to the compiler on MyProgrammingLab, it tells me that I have to "write the definition of the printAttitude method" or something like that. I have no idea how to do this and I looked at the API site and it looked kinda confusing... Could someone please lend a hand to this poor noob?Java Code:switch (numValues) { case 1 System.out.println("disagree"); break; case 2 System.out.println("no opinion"); break; case 3 System.out.println("agree"); break; default: }
- 04-10-2012, 04:05 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Re: The Switch Statement
Where is your printAttitude method? All we can see is a single switch statement ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-10-2012, 04:12 PM #3
Re: The Switch Statement
System.out.println("-text-");
prints the stuffs in a new line, and also skips to next line for successor statements..
for example,
output isJava Code:System.out.println("1st line"); System.out.print("2nd line"); System.out.print("3rd line");
note thatJava Code:1st line 2nd line3rd line
System.out.print();
requires a boolean or a string as an argument
regards
dhilip
- 04-10-2012, 04:14 PM #4
Re: The Switch Statement
- 04-10-2012, 04:16 PM #5
Re: The Switch Statement
- 04-10-2012, 04:19 PM #6
- 04-10-2012, 04:20 PM #7
Re: The Switch Statement
- 04-10-2012, 04:26 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Re: The Switch Statement
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-19-2012, 03:38 PM #9
Re: The Switch Statement
This is kinda old, but I never successfully figured this out. Would the code look something like this:
I feel like that "method does nothing" part is throwing me off...Java Code:public static void printAttitude(int); { case 1: System.out.println("disagree"); break; case 2: System.out.println("no opinion"); break; case 3: System.out.println("agree"); break; }
- 04-19-2012, 03:41 PM #10
Re: The Switch Statement
That's not the correct syntax for defining a method, taking a parameter, or for setting up a switch statement. They are all covered in the basic tutorials.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-20-2012, 03:12 PM #11
Re: The Switch Statement
- 04-20-2012, 03:29 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
Similar Threads
-
the switch statement and unreachable statement error
By name in forum New To JavaReplies: 2Last Post: 03-26-2012, 04:27 PM -
switch statement
By droidus in forum New To JavaReplies: 2Last Post: 09-21-2011, 09:54 AM -
help with switch statement
By java__beginner in forum New To JavaReplies: 4Last Post: 03-19-2009, 02:22 PM -
Demonstration of the switch statement
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
Switch Statement Help
By bluegreen7hi in forum New To JavaReplies: 6Last Post: 02-06-2008, 05:16 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks