Friday 15 July 2011

java - Why does it skip the "control" segment? -



java - Why does it skip the "control" segment? -

this question has reply here:

how compare strings in java? 23 answers

so i'm trying inquire user input value command right after sop done. skips reason.

public static void main(string [] args) { scanner keyboard = new scanner(system.in); system.out.println("what's balance?"); double initialbalance = keyboard.nextdouble(); business relationship chase = new account(initialbalance); system.out.println(chase + "; deposit or withdraw?"); string command = keyboard.nextline(); if(control == "deposit") { double deposit = keyboard.nextdouble(); system.out.println("how much deposit? " + deposit); chase.deposit(deposit); system.out.println(chase); } }

here snippet of code changes required.

scanner keyboard = new scanner(system.in); system.out.println("what's balance?"); double initialbalance = keyboard.nextdouble(); keyboard.nextline(); business relationship chase = new account(initialbalance); system.out.println("; deposit or withdraw?"); string command = keyboard.nextline(); if (control .equals("deposit") ){ system.out.println("how much deposit? " ); double deposit = keyboard.nextdouble(); keyboard.nextline();

the comments clear. need see 2 post pointed to. briefly there line separator comes in , importance of equals method , significance.

java

No comments:

Post a Comment