阅读背景:

我不断收到此错误:线程“main”中的异常java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:28

来源:互联网 

This is my code :

这是我的代码:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String tweet = scan.nextLine();

        int link = 0;
        int tag = 0;
        int at = 0;
        int c = 0;
        int l = tweet.length();

        if (l <= 140) {
            while (c < tweet.length()) {
                char let = tweet.charAt(c);
                if (let == '#') {
                    tag++;
                    String hash = tweet.substring(c, c + 2);
                    if (hash.equals("# ")) {
                        tag--;
                    }

                } else if (let == '@') {
                    at++;
                    String to = tweet.substring(c, c + 2);
                    if (to.equals("@ ")) {
                        at--;
                    }
                } else if (let == 'h') {
                    String http = tweet.substring(c, c + 7);
                    if (http.equals("https://")) {
                        link++;
                    }
                }
                c++;
            }
            System.out.println("Number of Hashtags: " + tag);
            System.out.println("Number of Attributions: " + at);
            System.out.println("Number of Links: " + link);
        } else if (l > 140) {
            int difference = tweet.length() - 140;
            System.out.print("Excess Characters: " + difference);
        }

    }
}
import java.util.



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: