String text = "sour";
System.out.println(text);
System.out.println(text.length());
System.out.println(text.charAt(2));
System.out.println(text.toUpperCase());
charAt指定取得字符串中的某个字符,索引从0开始。 toUpperCase为将小写字符改成大写。
char[] text1={'s','c','o','r','e'};
String score = new String(text1);
System.out.println(score);
通过String来合并char数组。
字符串就是连续的字符序列,由数字,字母和符号组成。
下面的程序是将字符串转化为整数使用了剖析类型Integer.parseInt转化为整数。
package base.taxt;
import java.util.Scanner;
//让用户输入整数,当输入0时候回计算之前输入的所有整数。
public class array {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int sum = 0;
int score= 0;
do {
System.out.println("请输入数字");
score =Integer.parseInt(scanner.nextLine());
sum+=score;
}while(score!=0);
System.out.println(sum);
}
}