本文共 505 字,大约阅读时间需要 1 分钟。
新姿势:Scanner
基本语法:
//从键盘接收数据
Scanner s = new Scanner(System.in);
import java.util.Scanner;public class java02 { //控制台输入两个整数,求和差积商后输出 public static void main(String[] args) { //从键盘中读取输入数据 Scanner s = new Scanner(System.in); //声明变量a和b,赋值为输入的整数 System.out.println("请输入第一个整数"); int a = s.nextInt(); System.out.println("请输入第二个整数"); int b = s.nextInt(); //计算a和b的和积差商 System.out.println("和="+(a+b)); System.out.println("差="+(a-b)); System.out.println("积="+(a*b)); System.out.println("商="+(a/b)); }}
转载地址:http://avnwi.baihongyu.com/