JAVA 读取

 

 

Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        System.out.println(a);
        double b = in.nextDouble();
        System.out.println(b);
        long c = in.nextLong();
        System.out.println(c);

        System.out.println(a + " " + b + " " + c);
        // in.next() , in.nextLine()和别的一起读会出错
        String s1 = in.nextLine();// 一个换行也会读取
        System.out.println("s1: " + s1);// dsfr fff ---> dsfr fff
        String s2 = in.next();
        System.out.println("s2 :" + s2);// dsfr fff ---> dsfr

 

 

        Scanner in = new Scanner(System.in);
        String str[] = new String[3];
        for (int i = 0; i < 3; i++) {
            str[i] = in.nextLine();
        }
        for (String x : str) {
            System.out.println(x);
        }


11dc fg
33334fv
b g  fs


11dc fg
33334fv
b g  fs

 

  Scanner in = new Scanner(System.in);
        String str[] = new String[3];
        char c[][] = new char[3][7];
        for (int i = 0; i < 3; i++) {
            str[i] = in.nextLine();
        }
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 7; j++) {
                c[i][j] = str[i].charAt(j);
            }
        }
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 7; j++) {
                System.out.print(c[i][j]);
            }
            System.out.println();
        }

11dc fg
33334fv
b g  fs


11dc fg
33334fv
b g  fs

 

posted on 2021-12-28 17:31  cltt  阅读(44)  评论(0编辑  收藏  举报

导航