Java 我的意图错误来自哪里?
我的程序中的一切似乎都运行良好,但出于某种奇怪的原因,每当它到达输入部分,您选择乘法或除法时,它就会终止程序,就像它已经完成一样 这个怎么了 我尝试过更改Java 我的意图错误来自哪里?,java,Java,我的程序中的一切似乎都运行良好,但出于某种奇怪的原因,每当它到达输入部分,您选择乘法或除法时,它就会终止程序,就像它已经完成一样 这个怎么了 我尝试过更改if(Choice.equals(Multiply)) 到“相乘”,另一个也一样 但是没有运气 这是我的密码: import java.util.Scanner; public class APJAVAPROGRAM { /** * @param args */ public static void
if(Choice.equals(Multiply))
到“相乘”
,另一个也一样
但是没有运气
这是我的密码:
import java.util.Scanner;
public class APJAVAPROGRAM {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner numberinput = new Scanner(System.in);
Scanner stringinput = new Scanner(System.in);
System.out.print("Input a numerator >>>"); // inputs first Numerator
double Numerator = numberinput.nextDouble();
System.out.print("Input a Denominator >>>"); // Inputs first denominator
double Denominator = numberinput.nextDouble();
System.out.print("Input a second numerator >>>"); //Inputs second Numerator
double Numerator2 = numberinput.nextDouble();
System.out.print("Input a second Denominator >>>"); // Inputs second denominator
double Denominator2 = numberinput.nextDouble();
System.out.println("Your entered fractions are " + Numerator + "/" + Denominator + " and "+ Numerator2 + "/" + Denominator2);
// Will print out the entered fractions
System.out.println("What would you like to do with these?"); //asks user what should be done
System.out.print("Multipy, Divide, Add, or Subtract >>>");
String Choice = stringinput.nextLine();
double Multiply = Numerator * Numerator2;
double Multiply2 = Denominator * Denominator2;
if(Choice.equals("Multiply"))
{
System.out.println(Multiply + "/" + Multiply2 + " Is your answer.");
// If the input is multiply it will do as such
}
else
{
double Divide = Numerator * Denominator2;
double Divide2 = Numerator2 * Denominator;
if(Choice.equals("Divide"))
System.out.println(Divide + "/" + Divide2 + " Is your answer.");
}
}
}
我刚刚运行了你的代码,没关系。这里是我得到的输入/输出:
Input a numerator >>>1
Input a Denominator >>>2
Input a second numerator >>>3
Input a second Denominator >>>4
Your entered fractions are 1.0/2.0 and 3.0/4.0
What would you like to do with these?
Multipy, Divide, Add, or Subtract >>>Multiply
3.0/8.0 Is your answer.
我刚刚运行了你的代码,没关系。这里是我得到的输入/输出:
Input a numerator >>>1
Input a Denominator >>>2
Input a second numerator >>>3
Input a second Denominator >>>4
Your entered fractions are 1.0/2.0 and 3.0/4.0
What would you like to do with these?
Multipy, Divide, Add, or Subtract >>>Multiply
3.0/8.0 Is your answer.
.equals(Object obj)
区分大小写,如果您输入的“乘法”或“除法”带有大写字母,它将正确运行
使用.equalsIgnoreCase(Object obj)
进行字符串到字符串的比较,忽略大小写注意事项.equals(Object obj)
区分大小写,如果使用大写字母键入“乘法”或“除法”,它将正确运行
使用
.equalsIgnoreCase(Object obj)
进行字符串到字符串的比较,忽略大小写注意事项您尝试过使用调试器吗?我在eclipse中使用了调试器,但没有找到任何东西。我只是在main()
方法中的IntelliJ中逐字转储了您的代码,它运行良好。如果你有一个可复制的样品,请发布一个。当它达到你想要它做什么的时候,它只是在那之后终止。但我找不到任何errorStyle提示:在Java中,变量(和方法)名称通常以小写字母开头。类名通常以大写字母开头。遵循一种语言通常使用的风格可以让其他人更容易阅读你的代码,也可以帮助你理解其他代码(因为你已经习惯了这种常见的风格)。你试过使用调试器吗?我在eclipse中使用了调试器,但没有发现任何东西我只是在main()中的我的IntelliJ中逐字地转储了你的代码
方法,它运行正常。如果你有一个可复制的样品,请发布一个。当它达到你想要它做什么的时候,它只是在那之后终止。但我找不到任何errorStyle提示:在Java中,变量(和方法)名称通常以小写字母开头。类名通常以大写字母开头。遵循一种语言通常使用的风格可以让其他人更容易阅读你的代码,也可以帮助你理解其他代码(因为你已经习惯了这种常见的风格)。谢谢你,我在这方面已经坚持了两个小时了谢谢你,我已经坚持了两个小时了