Results 1 to 2 of 2
  1. #1
    Hotspotmar is offline Member
    Join Date
    Sep 2011
    Rep Power

    Default Subsitution for while loop and text input

    I have a problem 1 i want to hit countdown the days till the end of the month and when done have a message to say that the program ends and i want text input so i can have a yes and no question heres the code, and sorry for the weird varibles i was feeling silly.

    import java.util.Scanner;

    class DERP_CLASS_2{

    public static void main(String args[]){
    Scanner water = new Scanner(;
    double loan = 0;
    double saving = 0;
    double days;
    double loan2;
    double money = 0;
    double loan1 = 0;
    double saving1 = 2;
    double loan3 = 0;

    System.out.println("How many days?");
    days = water.nextDouble();

    while (days <= 1);
    String input;
    System.out.println("How much money?");
    loan1 = water.nextDouble();

    System.out.println("Is marley saving?");

    String cat =;

    if(cat == "yes"){

    saving += saving1;
    loan2 = loan1;
    loan3 = loan1;
    while (loan1 > 9.99){
    loan1 -= 10;
    System.out.print("You owe:");
    System.out.print("Amount loaned:");
    System.out.println(loan2 - money);
    System.out.print("Extra:" + saving);

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Rep Power

    Default Re: Subsitution for while loop and text input

    Please use code tags when posting.

    Java Code:
    while (days <= 1);
    Firstly, the semicolon after the while statement means that the block that follows it is in no way associated with the while condition. Secondly, if you were to remove this semicolon then, assuming days <= 1 to begin with, it will never stop looping. (If it was an int, then eventually it would wrap around to 0x7FFFFFFF and evaluate to false, but as a double it'll get to the stage where the exponent is too large for subtracting 1 to make any difference to it.)

    Java Code:
    String cat =;
    if(cat == "yes"){
    Don't compare strings with ==. This compares object references, not string content. Use .equals() instead.

Similar Threads

  1. help me for this nested for loop with users input
    By jakemanalaotao in forum New To Java
    Replies: 4
    Last Post: 09-06-2011, 03:50 PM
  2. Loop returns at second input rather than first.
    By RockW in forum New To Java
    Replies: 2
    Last Post: 05-05-2011, 06:03 AM
  3. while loop bypasses scanner input on 2nd pass
    By xf021209 in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 08:10 AM
  4. [SOLVED] User Input - loop
    By new person in forum New To Java
    Replies: 4
    Last Post: 02-22-2009, 10:02 PM
  5. loop when there is no user-input
    By becky in forum New To Java
    Replies: 12
    Last Post: 02-02-2009, 10:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts