我不知道要添加到//Sample 3
什麼,任何人都可以幫助我,並告訴我我做錯了什麼?我正在寫來寫,如果假分數轉換成一個完整整數別的地方的最後一部分,但我不知道該怎麼寫我不確定如何處理我的代碼。分數轉換
package ch2_project;
import java.util.Scanner;
public class Ch2_project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a numerator: ");
int numerator = input.nextInt();
System.out.print("Enter a denominator: ");
int denominator = input.nextInt();
if (numerator < denominator)
{
System.out.println(numerator + "/" + denominator + " is a proper fraction"); // Sample 2
}
else
{
int mix = numerator/denominator;
int remainder = numerator % denominator;
System.out.println(numerator + "/" + denominator + " is a improper fraction and it's mixed fraction is " + mix + " and " remainder + "/" + denominator);// Sample 1
}
else if()
{
int whole = numerator/denominator
System.out.println(numerator + "/" + denominator + " is an improper fraction and it can be reduced to " + whole);//Sample 3
}
}
}
你做錯了什麼?是什麼讓你這麼想的。請解釋。意思是,告訴我們你的問題是什麼。 – Andreas
@imustbejulia:除了你要解決的問題之外,你的else和else子句的順序是倒退的,需要交換。 –