java中如何将字符串转化为字符_如何在Java中将字符串转换为运算符?

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-22 16:46   30   0

参见英文答案 >

Is it possible to pass arithmetic operators to a method in java?                                    8个

我试图在java中创建一个简单的基于文本的计算器,我的第一个程序,EVER,我无法弄清楚如何将输入字符串转换为变量opOne.然后,我将尝试使用opOne作为运算符对numTwo运行numOne.

代码如下:

import java.io.*;

import java.math.*;

public class ReadString {

public static void main (String[] args) {

System.out.print("Enter the first number: ");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int numOne = 0 ;

int numTwo = 0 ;

String opOne = null;

while(true){

try {

numOne = Integer.valueOf(br.readLine());

break;

} catch (IOException error) {

System.out.println("error; try again.");

System.exit(1);

}

catch (NumberFormatException nfe) {

System

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP