首先,这不是一个作业问题。我正在练习有关Java的知识。我想一个很好的方法是编写一个没有帮助的简单程序。不幸的是,我的编译器告诉我我不知道如何解决的错误。在不更改大量逻辑和代码的情况下,有人可以指出我的一些错误在哪里吗?谢谢
import java.lang.*;
import java.util.*;
public class Calculator
{
private int solution;
private int x;
private int y;
private char operators;
public Calculator()
{
solution = 0;
Scanner operators = new Scanner(System.in);
Scanner operands = new Scanner(System.in);
}
public int addition(int x, int y)
{
return x + y;
}
public int subtraction(int x, int y)
{
return x - y;
}
public int multiplication(int x, int y)
{
return x * y;
}
public int division(int x, int y)
{
solution = x / y;
return solution;
}
public void main (String[] args)
{
System.out.println("What operation? ('+', '-', '*', '/')");
System.out.println("Insert 2 numbers to be subtracted");
System.out.println("operand 1: ");
x = operands;
System.out.println("operand 2: ");
y = operands.next();
switch(operators)
{
case('+'):
addition(operands);
operands.next();
break;
case('-'):
subtraction(operands);
operands.next();
break;
case('*'):
multiplication(operands);
operands.next();
break;
case('/'):
division(operands);
operands.next();
break;
}
}
}
package org.com;
import java.lang.*;
import java.util.*;
public class Calculator
{
private int solution;
private static int x;
private static int y;
private char operators;
public Calculator()
{
solution = 0;
Scanner operators = new Scanner(System.in);
Scanner operands = new Scanner(System.in);
}
public int addition(int x, int y)
{
return x + y;
}
public int subtraction(int x, int y)
{
return x - y;
}
public int multiplication(int x, int y)
{
return x * y;
}
public int division(int x, int y)
{
solution = x / y;
return solution;
}
public void calc(int ops){
x = 4;
System.out.println("operand 2: ");
y = 5;
switch(ops)
{
case(1):
System.out.println(addition(x, y));
// operands.next();
break;
case(2):
System.out.println(subtraction(x, y));
// operands.next();
break;
case(3):
System.out.println(multiplication(x, y));
// operands.next();
break;
case(4):
System.out.println(division(x, y));
// operands.next();
break;
}
}
public static void main (String[] args)
{
System.out.println("What operation? ('+', '-', '*', '/')");
System.out.println(" Enter 1 for Addition");
System.out.println(" Enter 2 for Subtraction");
System.out.println(" Enter 3 for Multiplication");
System.out.println(" Enter 4 for Division");
Calculator calc = new Calculator();
calc.calc(1);
}
}
这会工作
本文向大家介绍简单探索 Java 中的惰性计算,包括了简单探索 Java 中的惰性计算的使用技巧和注意事项,需要的朋友参考一下 前言 惰性计算(尽可能延迟表达式求值)是许多函数式编程语言的特性。惰性集合在需要时提供其元素,无需预先计算它们,这带来了一些好处。 首先,您可以将耗时的计算推迟到绝对需要的时候。其次,您可以创造无限个集合,只要它们继续收到请求,就会继续提供元素。第三,map 和 filt
我似乎无法得到这个先进先出的计算工作: 我需要它从第一个数组@base中减去@subtr中的数字,一旦subt元素的总和超过@base数组的第一个元素,它就可以使用超出的数量,并从@base的第二个元素中减去,等等,直到完成为止。完成后,我需要它告诉我@base中的哪个数组结束了,该数组元素还剩多少(应该是1),然后还剩多少(应该是3)。提前谢谢!保罗
本文向大家介绍JavaScript编写简单的计算器,包括了JavaScript编写简单的计算器的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了JavaScript编写简单计算器的代码。分享给大家供大家参考。具体如下: 运行效果截图如下: 具体代码如下 js代码: 关于计算器的精彩文章请查看《计算器专题》 ,更多精彩等你来发现! 一个简单的计算器就是这样实现的,大家也可以利用javascri
这个挑战是创建一个简单的代数计算器,使用你所学到的关于解析的一切。你将需要设计一种语言,用于使用变量进行基本数学运算,为该语言创建 ABNF,并为其编写扫描器,解析器,分析器和解释器。这实际上对于简单的计算器语言可能是小题大做,因为不会有任何嵌套的结构,如函数,但是无论如何都要理解完整的过程。 挑战练习 简单的代数语言对于不同的人来说意思也不同,所以我希望你试试 Unix 命令bc。这是我运行bc
我正在为学校开发一个简单的JavaFX计算器,我被困在一起,我被困在一起,该事件从两个文本字段,选择的单选按钮以及按下计算按钮时执行该事件的输入放在一起。 节目预览
本文向大家介绍JS简单计算器实例,包括了JS简单计算器实例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了JS简单计算器的实现方法。分享给大家供大家参考。具体实现方法如下: 希望本文所述对大家的javascript程序设计有所帮助。