java-SE-3

xiaoxiao2021-02-28  68

输入输出

输入目前常用的就是标准输出流;System.out.println();

标准输入流为Scanner in=new Scanner(System.in);

int a=in.nextInt();String s=in.next();读取一个单词,以空格结尾;String s=nextLine();读取一整行;

double d=in.nextDouble();

检测是否还有下一个可读取

boolean hasNext();

boolean hasNextInt();

boolean hasNextDouble();

当然也有像c一样的输出形式System.out.printf();和c的printf()一样;还有String s=String.format("hello,%s, next year,you'll be %d,name,age);

转载请注明原文地址: https://www.6miu.com/read-68007.html

最新回复(0)