我已经测试了数字,并且它们保持正确的值,但它打印出的结果完全错误。 E.X:如果我把2/4,它输出1
这是我的代码:
import java.util.Scanner;
public class FractionConverter {
public static void main(String[] args) {
System.out.println("Welcome To The JEM Fraction Converter!\n");
Scanner sc = new Scanner(System.in);
String num = "0", choice;
System.out.println("Would You Like To Convert From 'Fraction - Decimal'(a) or 'Decimal - Fraction'(b)?");
choice = sc.nextLine();
if (choice.equalsIgnoreCase("a")) {
System.out.println("Please Enter A Fraction (x/y)");
num = sc.nextLine();
String[] parts = num.split("/");
String numerator = parts[0];
String denominator = parts[1];
double result = Double.parseDouble(numerator);
double result2 = Double.parseDouble(numerator);
System.out.println("\n" + numerator + "/" + denominator + " In Decimal Form Is: " + (result/result2));
}
}
}
感谢帮助!
答案 0 :(得分:1)
替换此行:
CXX = g++-5
CXXFLAGS = -std=c++11 -Wno-unknown-pragmas
INCLUDES = -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system -L/home/me/ogre_install/lib/OGRE/ -I/home/me/ogre_install/include/OGRE/ -L/home/me/ogre_install/lib/ -I/home/me/ogre_install/include/ -lOgreMain -lOgreOverlay -lOgreHlmsPbs -lOgreHlmsUnlit
all:
$(CXX) $(CXXFLAGS) $(INCLUDES) -o bin/a.out src/*
用这个:
double result2 = Double.parseDouble(numerator);
答案 1 :(得分:0)
double result = Double.parseDouble(numerator);
double result2 = Double.parseDouble(numerator);
......我想是复制/粘贴问题,不是吗? (两次分子)