I wrote this code
import java.util.*;
// Compiler version JDK 11.0.2
import java.util.Scanner;
class Dcoder
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int whole =0;
int secondWhole=0;
int num1=0;
int num2=0;
int secondNum1=0;
int secondNum2=0;
int result=0;
int choice=0;
int choice2=0;
int step=0;
int max=0;
int lcm=0;
int mu1=0;
int mu2=0;
int di1=0;
int di2=0;
System.out.println("press 1 if the first num is mixed and 2 if proper fraction");
choice = sc.nextInt();
System.out.println("press 1 if the second num is mixed and 2 if proper fraction");
choice2 = sc.nextInt();
if(choice == 1 && choice2 == 1){
System.out.println("enter the whole num");
whole = sc.nextInt();
System.out.println("enter the num1(numerator)");
num1 = sc.nextInt();
System.out.println("enter the num2(denominator)");
num2 = sc.nextInt();
int num3 = (whole*num2)+num1;
System.out.println("enter the second whole num");
secondWhole = sc.nextInt();
System.out.println("enter the second num1(numerator)");
secondNum1 = sc.nextInt();
System.out.println("enter the scond num2(denominator)");
secondNum2 = sc.nextInt();
int num4 = (secondWhole*secondNum2)+secondNum1;
if(num2 > secondNum2){
max = step = num2;
}
else if(num3<num4){
max = step = secondNum2;
}
while(num3!= 0) {
if( max % num2 == 0 && max % secondNum2 == 0) {
lcm = max;
break;
}
max += step;
}
System.out.println("what do you want to do(+/-)");
String Expression = sc.nextLine();
if(Expression == "+"){
di1 =lcm/num2;
mu1 =di1*num3;
di2 =lcm/secondNum2;
mu2 =di2*num4;
result = mu1 +mu2;
}
else if(Expression == "-"){
di1 =lcm/num2;
mu1 =di1*num3;
di2 =lcm/secondNum2;
mu2 =di2*num4;
result = mu1 -mu2;
}
System.out.println("result = "+result+"/"+lcm);
}
}
}
The computer doesn't process this
if(Expression == "+"){
di1 =lcm/num2;
mu1 =di1*num3;
di2 =lcm/secondNum2;
mu2 =di2*num4;
result = mu1 +mu2;
}
else if(Expression == "-"){
di1 =lcm/num2;
mu1 =di1*num3;
di2 =lcm/secondNum2;
mu2 =di2*num4;
result = mu1 -mu2;
But shows the result yeah it's wrong It's shows this
press 1 if the first num is mixed and 2 if proper fraction
1
press 1 if the second num is mixed and 2 if proper fraction
1
enter the whole num
2
enter the num1(numerator)
1
enter the num2(denominator)
3
enter the second whole num
3
enter the second num1(numerator)
1
enter the scond num2(denominator)
5
what do you want to do(+/-)
result = 0/15
Process finished.
Please help
Aucun commentaire:
Enregistrer un commentaire