• Java常用的输入输出


    一、输入

    1.使用Scanner类:

    (1)使用java.util包。 import java.util.*;

    (2)构造Scanner类对象,它附属于标准输入流System.in。 Scanner s = new Scanner(System.in);

    (3)常用的next()方法系列:

    nextInt():输入整数

    nextLine():输入字符串

    nextDouble():输入双精度数

    next():输入字符串(以空格作为分隔符)

            Scanner s=new Scanner(System.in);
            System.out.println("输入一个整数:");
            int i = s.nextInt();
            System.out.println("输入一个双精度浮点数:");
            double d = s.nextDouble();
            System.out.println("输入一个字符串:");
            String sc = s.next();     //也可以用nextLine()去掉next()支持传入空格
            s.close();  //不关闭会有警告

    二、输出

    System.out.println("输入的整数为:"+i);//不换行打印
    System.out.println("输入的浮点数为:"+d);
    System.out.printf("输入的字符串为:%s\n", sc);//按格式输出


    System.out.write(2222); //字节输出,用着不方便所以不常用。
  • 相关阅读:
    android slidingview
    关于打工
    android开发基本流程
    android and javascript
    android listview and scrollview
    google收购的公司
    android反编译
    android资料
    colors
    【读书笔记】-- 文本可视化研究综述
  • 原文地址:https://www.cnblogs.com/StarZhai/p/15967879.html
Copyright © 2020-2023  润新知