나는 프로젝트를 수행하고 있으며 소수점부터 소수점까지 내 변환기에 어떤 문제가 있는지 알고 싶습니다. 그리고 그것은 방법으로 끝나야합니다. 대신 코드로,자바의 십진법 변환기에서 내 소수점 이하 자릿수를 알아 내고 싶습니다.
import java.util.*;
public class Fraction {
method();
}
public void method() {
Scanner sc = new Scanner (System.in);
System.out.println("Please enter the numerator: ");
double numerator = sc.nextInt();
System.out.println("Please enter the Denominator: ");
double denominator = sc.nextInt();
if (denominator == 0) {
System.out.println("Can't divide by zero");
}
else {
double fraction = (double)numerator/denominator;
System.out.println(fraction);
}
}
이 시도 :
import java.util.Scanner;
public class Fraction
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int numerator, int denominator, result;
System.out.println ("Please enter the numerator: ");
num = input.nextInt();
System.out.println ("Please enter the denominator: ");
den = input.nextInt();
result = double(numerator/denominator);
}
public static int double(int x)
{
if (denominator == 0){
System.out.println ("Can't divide by zero");
}
else {
double fraction = (double)numerator/denominator;
System.out.println(fraction);
}
}
}
무엇 ? 예상되는 결과는 무엇입니까? – Mauren
사용자가 분자를 입력하고 분모를 입력하고 싶습니다. 그 숫자에서 double을 만들고 그 분수의 십진수를 계산하십시오. – ZacharyRW
분자와 분모가 매개 변수가 아니라 주 메뉴에 국한되어 있기 때문에 컴파일하지 않는 것으로 추측합니다. –