都在System.out模块下,常用方法有:
print:输出;
println:输出并换行;
printf:格式化输出;
格式化输出的方法是System.out.printf(),这里和C语言的格式化输出的方法名字相同,且输出方法相同
System.out.printf("%f,%d,%s,..." , val1,val2,val3,...)
占位符 | 说明 |
%d | 整数 |
%x | 十六进制整数 |
%f | 浮点数 |
%e | 科学计数法表示的浮点数 |
%s | 字符串 |
import java.util.Scanner; public class Main{ public static void main(String [] args){ Scanner scanner = new Scanner(System.in); String str=scanner.nextLine();//读取输入的字符串 int n=scanner.nextInt();//读取输入的整数 //之后输入内容就保存在了str和n中 } }
原文:https://www.cnblogs.com/ShineLeBlog/p/14701644.html