Results 1 to 4 of 4
- 03-06-2011, 07:44 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 71
- Rep Power
- 0
compiles but I get errors, need help
when ever I run it I always get an error when it displays change or how many years to wait, any one wanna help me out here?
Java Code:import java.util.Scanner; public class Lab6_1 { public static void main(String[] args) { int customerAge; int reqAge; int waitYears; double cashAmount; double cashReq; double cashNeeded; System.out.println("Please type customer age:"); Scanner keyboard = new Scanner(System.in); customerAge = keyboard.nextInt(); System.out.println("Type customer cash amount:"); cashAmount = keyboard.nextDouble(); reqAge = 21; cashReq = 5.00; waitYears = reqAge - customerAge; cashNeeded = cashReq - cashAmount; if (customerAge >= 21) { if (cashAmount >= 5.00) System.out.println("Congratulations, you can have some beer." ); else System.out.printf("Sorry, you need $%.2 more.%n" , cashNeeded); } else { System.out.println("No beer for you!"); System.out.printf("Come back in %.1f years. %n" , waitYears ); } System.out.println("Thank you for your patronage."); } }
-
- 03-06-2011, 08:05 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 71
- Rep Power
- 0
well it works for me now, turns out I forgot the "f" after %.2 in the printf statement lol, but the friend I'm trying to help with this is still getting problems. I'll ask them for the errors they are getting
- 03-06-2011, 08:29 PM #4
Member
- Join Date
- Feb 2011
- Posts
- 71
- Rep Power
- 0
Similar Threads
-
setBounds not working (no errors; runs and compiles fine)
By cc11rocks in forum AWT / SwingReplies: 6Last Post: 02-08-2011, 02:29 AM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
compiles but dosent work...
By darkflame5019 in forum New To JavaReplies: 8Last Post: 01-01-2011, 07:22 PM -
compiles; no display
By skuzzie in forum New To JavaReplies: 5Last Post: 12-18-2010, 07:57 PM -
Errors driving me crazy! although compiles fine
By irishsea2828 in forum New To JavaReplies: 1Last Post: 04-08-2008, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks