Results 1 to 4 of 4
- 01-06-2010, 09:15 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 68
- Rep Power
- 0
problems with parsing a string into int,
output:Java Code:public static void main(String[] args) throws IOException { String firstSlot, secondSlot, thirdSlot; int firstPiece, secondPiece, thirdPiece, payOff; System.out.print("Enter The Coins: "); int coins = Integer.parseInt(br.readLine()); System.out.print("\n"); while (coins != 0) { System.out.print("Bet(Max: 1 - 4 Coins): "); int bet = Integer.parseInt(br.readLine()); firstPiece = (int) Math.floor(Math.random() * MAX_PIECES) + 1; secondPiece = (int) Math.floor(Math.random() * MAX_PIECES) + 1; thirdPiece = (int) Math.floor(Math.random() * MAX_PIECES) + 1; switch (firstPiece) { case 1: firstSlot = "BELL"; break; case 2: firstSlot = "CHERRY"; break; case 3: firstSlot = "GRAPE"; break; case 4: firstSlot = "------"; break; // just in case, there is still an option default: firstSlot = "------"; break; } switch (secondPiece) { case 1: secondSlot = "BELL"; break; case 2: secondSlot = "CHERRY"; break; case 3: secondSlot = "GRAPE"; break; case 4: secondSlot = "------"; break; // just in case, there is still an option default: secondSlot = "------"; break; } switch (thirdPiece) { case 1: thirdSlot = "BELL"; break; case 2: thirdSlot = "CHERRY";; break; case 3: thirdSlot = "GRAPE"; break; case 4: thirdSlot = "------"; break; // just in case, there is still an option default: thirdSlot = "------"; break; } if (firstSlot.equals("BELL") && secondSlot.equals("BELL") && thirdSlot.equals("BELL")) { System.out.println("Lucky One!"); } System.out.print("\n"); System.out.format("%2d %10s %10s %10s", firstSlot, secondSlot, thirdSlot); System.out.print("\n\n"); coins = coins - bet; } // end of while loop } }
help! :confused:Java Code:Enter The Coins: 50 Bet(Max: 1 - 4 Coins): Bet(Max: 1 - 4 Coins): 2 Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999) at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2709) at java.util.Formatter$FormatSpecifier.print(Formatter.java:2661) at java.util.Formatter.format(Formatter.java:2433) at java.io.PrintStream.format(PrintStream.java:920) at xxTestxx.Ch6Exercise31.main(Ch6Exercise31.java:83)
- 01-06-2010, 09:18 AM #2
Member
- Join Date
- Dec 2009
- Posts
- 68
- Rep Power
- 0
solved, tnx ..!! sorry...
- 01-06-2010, 09:18 AM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
In
You pass three arguments but have 4 format specifiers.Java Code:System.out.format("%2d %10s %10s %10s", firstSlot, secondSlot, thirdSlot);
- 01-06-2010, 10:32 PM #4
It would be helpful if you can mark this thread as [SOLVED].
To do so, do the following:
1. Find "Post Reply" button on the top of this thread.
2. Look exactly right of it until you see "Thread Tools." (between LinkBack and Thread Tools)
3. Click on "Thread Tools" and on the drop down menu, click on "Mark as solved."
Similar Threads
-
Parsing string and simple calculation
By sapina007 in forum Advanced JavaReplies: 4Last Post: 08-21-2009, 12:07 PM -
Parsing XML
By virvalid in forum Advanced JavaReplies: 3Last Post: 08-10-2009, 12:40 PM -
Multi Delimeter String Parsing
By yuriyl in forum Advanced JavaReplies: 5Last Post: 07-13-2009, 03:34 PM -
parsing numbers in a string
By rsoler in forum Advanced JavaReplies: 4Last Post: 03-31-2009, 06:05 AM -
Problems implementing Java string methods
By everlast88az in forum New To JavaReplies: 8Last Post: 11-06-2008, 04:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks