java中如何输入字符

char m = input.next().charAt(0);

下面是ACM中的模拟计算器的题目,以此作为示例:

import java.util.*;
public class Main {
public static void main(String[] args){

Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
char c = in.next().charAt(0);
switch(c)
{
case '+':
System.out.printf("%d",a+b);
break;
case '-':
System.out.printf("%d",a-b);
break;
case '*':
System.out.printf("%d",a*b);
break;
case '/':
if(b!=0)
{
System.out.printf("%d",a/b);
}
break;
}
}
}

--------------------- 本文来自 &Ghost 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/m17865923255/article/details/50707899?utm_source=copy

猜你喜欢

转载自blog.csdn.net/qq_41815040/article/details/82933527