关于字符串的一些基础

 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);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值