我不知道如何表示分数。我应该根据用户输入的分数和分母添加两个分数。这项活动要求我做的是将此作为打印结果。Java中的分数
第一个分数的分子是多少? 1
第一部分的分母是多少? 2
第二部分的分子是多少? 2
第二个分数的分母是多少? 5
的1/2 + 2/5 = 9/10
的数字的问题后的总和可以基于用户输入来改变。
下面你可以看到我写的东西。
public class AddFractions extends ConsoleProgram
{
public void run()
{
int numeratorFirst = readInt("What is the numerator of the first fraction?");
int denominatorFirst = readInt("What is the denominator of the first fraction?");
int numeratorSecond = readInt("What is the numerator of the second fraction?");
int denominatorSecond = readInt("What is the denominator of the second fraction?");
}
}
好,用英语思考的第一个问题。假设你有'1/2'和'2/5'数字。下一步你需要做什么来获得你的结果? – Kayaman
欢迎来到StackOverflow!当问一个问题时,请添加一些与手头问题相关的代码,以便我们看到您尝试了什么,以及您可能在错误的方向上进行了哪些操作。现在你的问题是,你只有输入数字的(伪)代码 - 除了它们都涉及数字外,它们并不涉及分数。请尝试自己解决问题,如果您有任何具体(非“给我的代码”)问题,请随时[问一个好问题](http://stackoverflow.com/help/how-to-问),我们很乐意提供帮助。 –