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

  • Java
  • Thread starter aldofo
  • Start date
  • #1
1
0

Main Question or Discussion Point

here is
Code:
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
 

Answers and Replies

  • #2
384
35
Well, structurally your program should then look like
Code:
do {
  ask_for_interval_bound
  print_the_odd_numbers_within_this_interval
} while user_want_to_continue
 

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

Replies
8
Views
1K
  • Last Post
Replies
4
Views
2K
Replies
4
Views
10K
Replies
2
Views
2K
  • Last Post
Replies
3
Views
949
Replies
7
Views
6K
  • Last Post
Replies
6
Views
2K
Replies
11
Views
571
Replies
18
Views
8K
Replies
20
Views
30K
Top