1、读取输入
(12条消息) ACM之Java输入输出_shijiebei2009的博客-CSDN博客_acm输入输出
java的collection中的各种集合
str.append(i);
改变字符串的内容,原来的字符串是“1”,append“2”以后,就变成“12”,返回的是stringbuilider,变成string要再讨一个tostring
str.indexOf('2',position+1);
找字符串中“2”的位置,第二个参数的作用是从某个位置开始。
str.toUpperCase()
String reverse = new StringBuffer(str).reverse().toString();
System.out.format("%.3f",num);
String.format("%2d", num).replace(" ", "0");
7变成07,空格用0补足。
System.out.printf("%f\n",pi);//"f"表示格式化输出浮点数
System.out.printf("%d\n",i);//"d"表示格式化输出十进制整数
System.out.printf("%o\n",i);//"o"表示格式化输出八进制整数
System.out.printf("%x\n",i);//"x"表示格式化输出十六进制整数
System.out.printf("%s\n",str);//"s"表示格式化输出字符串
System.out.printf("一个字符串:%s,一个浮点数:%f,一个整数:%d",str,pi,i);//可以一次输出多个变量,注意顺序即可
MathContext mc = new MathContext(6);
BigDecimal b = new BigDecimal(a);
System.out.println(b.divide(BigDecimal.ONE,mc));
mc是保留的位数,BigDecimal.ONE是BigDecimal类里的1.
public static void main(String[] args)
{
String Colors="Red,Black,White,Yellow,Blue";
String[] arr1=Colors.split(","); //不限制元素个数
String[] arr2=Colors.split(",",3); //限制元素个数为3
System.out.println("所有颜色为:");
for(int i=0;i
String str3 = new String("acount=? and uu =? or n=?");
System.out.println("多个分隔符返回值 :" );
for (String retval: str3.split("and|or")){
System.out.println(retval);
}
char a=String.charAt(num)
replaceFirst
String words = "hello java,hello php";
String newStr = words.replaceFirst("hello","你好 ");
System.out.println(newStr); // 输出:你好 java,hello php
replaceAll
String words = "hello java,hello php";
String newStr = words.replaceAll("hello","你好 ");
System.out.println(newStr); // 输出:你好 java,你好 php