中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      java的輸入語句小結

      時間:2024-08-02 14:43:00 JAVA認證 我要投稿
      • 相關推薦

      java的輸入語句小結

        Java中做輸入的方式:通過控制臺輸入數據,需要使用Scanner對象來操作,那么java輸入語句到底有哪些呢?下面跟yjbys小編一起來看看吧!

        1.使用Scanner

        使用時需要引入包import java.util.Scanner;首先定義Scanner對象

        Scanner sc = new Scanner(System.in);

        如果要輸入整數,則 int n = sc.nextInt();

        String類型的,則String temp = sc.next();

        比如:

        import java.util.Scanner;

        public class Test {

        public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        int month = -1;

        while(true) {

        try {

        System.out.print("請輸入月份:");

        month = scanner.nextInt();

        if(month >= 1 && month <= 12) {

        break;

        }

        System.out.println("** 請輸入正確的月份 **");

        } catch (Exception e) {

        System.out.println("** 格式錯誤!請輸入數字 **");

        scanner.next();

        }

        }

        System.out.println(month + " 月份有:" + days[month - 1] + " 天");

        }

        }

        2.使用BufferedReader

        用前需要引入 import java.io.Reader;

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

        String input = br.readLine();

        比如:

        ==================================================================================================

        import java.io.*;

        public class importtext {

        public static void main(String[] args) {

        String st;

        int num;

        float fnum;

        try{

        System.out.print("輸入:");

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

        st = br.readLine();

        System.out.print("輸入一個數:");

        num = Integer.parseInt(br.readLine());

        System.out.print("輸入一個浮點數:");

        fnum = Float.parseFloat(br.readLine());

        System.out.print("輸出:"+st+'n');

        System.out.print("輸出:"+num+'n');

        System.out.print("輸出:"+fnum+'n');

        }catch(IOException e){}

        }

        }

        ==================================================================================================

        package com.s2;

        import java.io.*;

        public class Input

        {

        public static void main(String[] args)throws IOException

        {

        while(true)

        {

        BufferedReader buf;

        String str;

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

        System.out.println("Input a string:");

        str=buf.readLine();

        System.out.println("String="+str);

        }

        }

        }

        ==================================================================================================

        應該注意的是:Java把從鍵盤輸入的數據一律看作是字符串,因此若要從鍵盤輸入并讓系統認可是數值型數據,必須經過轉換。

        比如:

        package com.s2;

        import java.io.*;

        public class Input

        {

        public static void main(String[] args)throws IOException

        {

        while(true)

        {

        int num;

        BufferedReader buf;

        String str;

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

        System.out.println("Input an integer:");

        str=buf.readLine();

        num=Integer.parseInt(str);

        System.out.println("String="+str);

        System.out.println("Integer="+str);

        }

        }

        }

      【java的輸入語句小結】相關文章:

      Java入門基礎知識:Java IO(輸入/輸出)03-07

      JAVA認證基礎知識:JavaNativeInterface學習小結01-11

      日語輸入法的輸入規則12-08

      PPT文字輸入詳細教程03-29

      鼠標輸入法介紹03-21

      word中輸入分數的方法03-04

      在word中如何輸入分數12-01

      如何選擇輸入法03-05

      java中continue跳轉語句使用方法03-29

      主站蜘蛛池模板: 石河子市| 丰满熟妇人妻av无码区| 色综合久久五月天久久久| 国产精品伦理av一区二区| 久久精品无码一区二区三区不卡| 中文字幕一区二区三区日韩网| 国产美女裸身网站免费观看视频| 国产av天堂亚洲国产av麻豆| 宜兰市| 午夜亚洲精品中文字幕| 天堂最新在线官网av| 狠狠综合亚洲综合亚色| 鸡西市| 国产一区二区三区国产精品| 久久精品国产成人午夜福利| 伊人不卡中文字幕在线一区二区| 超碰性爱| 津市市| 无码高潮少妇毛多水多水免费| 亚洲一区二区精品在线播放| 波多野结衣一区二区三区免费视频| 色婷婷一区二区三区四区| 26uuu欧美日本在线播放| 丽水市| 紫阳县| 国产成人香蕉久久久久| 天堂av在线免费播放| 粉嫩av一区二区在线观看| 丝袜熟女视频九色一区91| 免费国产在线精品三区| 包头市| 成人国产精品高清在线观看| 精品少妇后入一区二区三区| 人妻少妇久久精品一区二区| 污污污国产免费网站| 国产精品毛片av久久| 看全色黄大色大片免看的| AV无码人妻一区二区三区牛牛| 芮城县| av福利免费在线观看网站| 国产精品免费av一区二区|