i have rewritten this in a do while loop but how can i make the division part retun/accept just three decimal place for example is if i get 1/4 i should be able to enter 0.25 and also if i get 1/7 i should be able to get 0.14.
import java.util.*;
public class HelloWorld
{
public static void main (String[] args)
{
Scanner keyboard=new Scanner(System.in);
Random quest=new Random();
int module,range,number,count,quest1,quest2,answer,score;
double result;
System.out.print("Enter module(1 for addition, 2 for subtraction, 3 for multiplication, 4 for division, -1 for exit)?");
module=keyboard.nextInt();
do{
System.out.print("Enter range of numbers(1-100)");
range=keyboard.nextInt();
System.out.print("How many questions do you want to practice(minimum 3)?");
number=keyboard.nextInt();
count=1;
score=0;
result=0;
while (count<= number)
{
quest1=quest.nextInt(range)+1;
quest2=quest.nextInt(range)+1;
if (module==1)
{
result=quest1+quest2;
System.out.print(quest1+"+" +quest2+"=");
}
else
{
if (module==2)
{
result=quest1-quest2;
System.out.print(quest1+"-" +quest2+"=");
}
else
{
if (module==3)
{
result=quest1*quest2;
System.out.print(quest1+"*" +quest2+"=");
}
else
{
if (module==4)
{
result=(double)quest1/quest2;
System.out.print(quest1+"/" +quest2+"=");
}
}
}
}
answer=keyboard.nextInt();
if(answer==result)
{
score=score+1;
System.out.println("you are correct!");
}
else {
System.out.println("You are wrong, the correct answer is " +result);
}
count=count+1;
if(count>number)
{
System.out.println("you scored "+score+" out of "+number+".");
count=1;
score=0;
break;
}
}
System.out.print("Enter module(1 for addition, 2 for subtraction, 3 for multiplication, 4 for division, -1 for exit)?");
module=keyboard.nextInt();
}while((module>0) && (module<5));
System.out.println("The program is terminating......");
}
}