Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I need help with this java program that has to use do while loop?

  1. Oct 30, 2011 #1
    here is
    Code (Text):
    import java.util.*;

    public class oddNumbers


    {
    public static void main(String[] args){
    System.out.println("enter two number");
    Scanner kb=new Scanner(System .in);


    int number=kb.nextInt();
    int number2=kb.nextInt();
    int s=number2/2;
    String decision;





    while(number>number2)
    {
    System.out.println("Error enter input again");
    number=kb.nextInt();
    number2=kb.nextInt();
    s=number2/2;

    }

    do{

    System.out.println(number*2);
    number++;



    System.out.println("do you want to continue");

    ddecisionkb.nextLine();





    }while (decisionequals("yes")||decisionquals("Y…



    }
    }

    this code asks the user every time that this program prints a odd number, but I want to print all the odd numbers and them ask the user.

    this is what i have to do.
    Write a program that asks the user to enter two numbers. The program should display all the odd numbers between the two numbers. The program will ask the user if he wishes to perform the operation again. If so, it should repeat, otherwise it should terminate
     
  2. jcsd
  3. Oct 30, 2011 #2
    Well, structurally your program should then look like
    Code (Text):

    do {
      ask_for_interval_bound
      print_the_odd_numbers_within_this_interval
    } while user_want_to_continue
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: I need help with this java program that has to use do while loop?
Loading...