d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need More Help..
Add Reply New Topic New Poll
Member
Posts: 9,274
Joined: May 4 2010
Gold: 0.01
Feb 14 2013 12:14pm
I shouldn't of taken the online version of this class. I'm trying to setup a continuing while loop if the user inputs a Y to continue but discontinue the loop if the user inputs a N.

Code
import java.util.Scanner;

public class NumberBounds {

public static void main(String[] args)  {
 Scanner keyboard = new Scanner(System.in);
 
 boolean continueflag = true;

 while (continueflag)
 {

  System.out.println("Enter a number");
  int starting_number = keyboard.nextInt();

  System.out.println("Enter a Upper Bound");
  int upper_bound = keyboard.nextInt();

  System.out.println("Enter a addition increment");
  int step_size = keyboard.nextInt();
  starting_number += step_size;

  int count = 0;

  while (starting_number <= upper_bound)
    {
              System.out.print(starting_number + " ");
              starting_number += step_size;

              count += 1; if ((count % 10) == 0)
                  System.out.println();
          }
 
   System.out.print("Would you like to continue enter Y or N?");
   if (Y)
    continueflag = false;
 }

}
}
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Feb 14 2013 01:36pm
Quote
  System.out.print("Would you like to continue enter Y or N?");
  if (Y)
    continueflag = false;


What do you expect these lines to do, exactly?
Member
Posts: 2,478
Joined: Jan 4 2007
Gold: 7,545.00
Feb 14 2013 02:27pm
A few problems with the lines irimi pointed out.

1) You're not capturing the users input.
2) If the user says yes they want to continue, why would you set the flag to false?
3) That if statement is not right.


Try taking a look at these lines

Code
System.out.println("Enter a addition increment");
 int step_size = keyboard.nextInt();
 starting_number += step_size;


And figure out what's happening. Try and do something similar to this but with Strings.

If you're not sure what a String is, google it.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll