国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java獲取鍵盤輸入值

2019-11-14 12:28:48
字體:
來源:轉載
供稿:網友
java獲得鍵盤輸入的值得方法有:方法一,使用System.in.read。例如:
1public static void main(String  args[]) throws IOException{
2  System.out.PRint("請輸入:");
3  char i = (char) System.in.read();
4  System.out.println(" aaa:"+i);
5}
方法二,使用BufferedReader。例如:
1public static void main(String  args[]) throws IOException{
2  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
3  String str = null;
4  System.out.println("請輸入:");
5  str = br.readLine();
6  System.out.println("aaaa :"+str);
7}
方法三,使用Scanner,可以輸入不同的類型.例如:
01public static void main(String  args[]) {
02  Scanner sc = new Scanner(System.in);
03  System.out.println(“請輸入你的姓名:”);
04  String name = sc.nextLine();
05  System.out.println(“請輸入你的年齡:”);
06  int age = sc.nextInt();
07  System.out.println(“請輸入你的工資:”);
08  float salary = sc.nextFloat();
09  System.out.println(“你的信息如下:”);
10  System.out.println(“姓名:”+name+“/n”+“年齡:”+age+“/n”+“工資:”+salary);
11}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绵竹市| 珲春市| 乌审旗| 上杭县| 石景山区| 兴仁县| 会东县| 西畴县| 武鸣县| 沽源县| 海门市| 九龙坡区| 定州市| 南皮县| 鄂尔多斯市| 长垣县| 芦溪县| 荆州市| 香港| 衡水市| 漾濞| 湘阴县| 五台县| 同心县| 云安县| 黑山县| 个旧市| 武威市| 津市市| 万宁市| 乐陵市| 阳东县| 紫阳县| 大英县| 诏安县| 永兴县| 安顺市| 吉林市| 休宁县| 绩溪县| 郸城县|