Results 1 to 2 of 2
- 01-30-2012, 04:31 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 24
- Rep Power
- 0
Not able to enter input with String variable set to Scanner
I just wrote this to practice and for some reason when I run it it won't let me enter input on "answer = scan.nextLine();" after the second print statement. Appreciate the help.
Java Code:import java.util.Scanner; public class FirstProgram { public static void main(String args[]){ Scanner scan = new Scanner(System.in); double balance, withdraw, deposit; String answer; System.out.println("What is your bank balance?"); balance = scan.nextDouble(); System.out.println("Would you like you make a withdraw, or a deposit?"); answer = scan.nextLine(); if(answer.equalsIgnoreCase("withdraw")) { System.out.println("How much would you like to withdraw?"); withdraw = scan.nextDouble(); balance = balance - withdraw; System.out.println("Your current balance is: " + balance); } else if (answer.equalsIgnoreCase("deposit")) { System.out.println("How much would you like to deposit?"); deposit = scan.nextDouble(); balance = balance + deposit; System.out.println("Your current balance is: " + balance); } } }
- 01-30-2012, 04:41 AM #2
Member
- Join Date
- Jan 2012
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Scanner.Next(Long/String/Double) - How do I skip the input?
By Illanair in forum New To JavaReplies: 2Last Post: 01-10-2012, 01:10 PM -
That old problem with scanner and end of line (enter)
By Java Riser in forum New To JavaReplies: 2Last Post: 09-29-2011, 01:54 AM -
End Scanner int input with text value
By BillyB in forum New To JavaReplies: 3Last Post: 03-07-2011, 05:13 PM -
how to enter input method name for getMethod(------)
By Dayanand in forum New To JavaReplies: 3Last Post: 02-23-2011, 06:07 PM -
enter a string sentence
By amorosa19 in forum New To JavaReplies: 11Last Post: 01-28-2009, 04:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks