gpt4 book ai didi

java - 我的意图错误来自哪里?

转载 作者:行者123 更新时间:2023-12-02 03:24:55 26 4
gpt4 key购买 nike

我的程序中的一切似乎都工作正常,但由于某种奇怪的原因,每当它到达您选择乘法或除法的输入部分时,它就会终止程序,就像它已经完成一样。

这有什么问题吗?

我尝试更改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.");




}
}
}

最佳答案

.equals(Object obj) 区分大小写,如果您输入大写字母“乘”或“除”,它会正确运行。

使用.equalsIgnoreCase(Object obj)进行字符串与字符串的比较,忽略大小写考虑

关于java - 我的意图错误来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39092912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com