gpt4 book ai didi

java - 处理数学公式

转载 作者:行者123 更新时间:2023-12-02 11:31:19 25 4
gpt4 key购买 nike

我希望能够制作一个使用以下公式的程序:

z= 1/y (x) 

我想问以下问题:

  1. 输入今年发生的次数(这部分我知道该怎么做)(y)

  2. 今天发生了多少次(x)

到目前为止我唯一拥有的是……

import java.util.Scanner;
import javax.swing.JOptionPane;

public class javaCalculator
{

public static void main(String[] args)
{
int num1;
int num2;
String operation;


Scanner input = new Scanner(System.in);

System.out.println("please enter the first number");
num1 = input.nextInt();

System.out.println("please enter the second number");
num2 = input.nextInt();

Scanner op = new Scanner(System.in);

System.out.println("Please enter operation");
operation = op.next();

if (operation == "+");
{
System.out.println("your answer is" + (num1 + num2));
}
if (operation == "-");
{
System.out.println("your answer is" + (num1 - num2));
}

if (operation == "/");
{
System.out.println("your answer is" + (num1 / num2));
}
if (operation == "*")
{
System.out.println("your answer is" + (num1 * num2));
}


}
}

有人可以帮忙吗?

谢谢! (我在高中,想输入我制作的公式,但我还需要将其转换为html..

最佳答案

您可以尝试如下操作:

import java.util.Scanner;

class ComputeXbyY
{
public static void main(String args[])
{
// Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);

System.out.println("Please enter: y - ");
int y = in.nextInt();
System.out.println("You entered y "+y);

System.out.println("Please enter: x - ");
int x = in.nextInt();
System.out.println("You entered x "+x);

if(y!=0){
float res = (float)x/(float)y;
System.out.println("Result: "+res);
}
in.close();
}
}

关于java - 处理数学公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49284662/

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