获取键盘输入

Author Avatar
Roojay 6月 16, 2017
  • 在其它设备中阅读本文章
/**
Java获取键盘输入值
*/
public static void main(String args[]){
  Scanner sc = new Scanner(Systen.in);
  String s = sc.nextLine(); //接受字符和字符串类型的输入
  int age = sc.nextInt();
  float salary = sc.nextFloat();
}

简单运行、退出方法

import java.util.Scanner;
public class Test {
    public static void main(String args[]) {
        int t = 1;
itcast :
        while(t > 0) {
            System.out.println("1.运行:\n" + "2.退出:");
            Scanner sc1 = new Scanner(System.in);
            int i = sc1.nextInt();
            switch(i) {
            case 1:
                //这里输入具体的计算程序
                break;
            case 2:
                break itcast;
            default:
                System.out.println("输入有误,请重新输入");
                break;
            }
        }
    }
}

The MIT License (MIT)
Copyright (c) 2019, Roojay.

本文链接:https://roojay.com/pages/828295ba/