开发者社区> 问答> 正文

Java性能优化,如何快速找出所有大写字符串

Java性能优化,如何快速找出所有大写字符串

展开
收起
道月芬1 2021-11-01 11:50:39 2368 0
2 条回答
写回答
取消 提交回答
  • import java.io.*;

    import java.util.*;

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

    //Uppercase

    String isUp = "";

    System.out.print("Please give a string: ");

    String x = in.next();

    int z = x.length();

    for(int y = 0; y <= z; y++){ if(Character.isUpperCase(x.charAt(y))){ char w = x.charAt(y);

    isUp = isUp + w + " ";

    }

    }

    System.out.println("The uppercase characters are " + isUp);

    //Uppercase

    }

    }

    2021-11-03 14:19:30
    赞同 展开评论 打赏
  • never say never~

    Exception in thread "main" java.lang.StringIndexOutOfBoundsException:

    String index out of range: 4

    at java.lang.String.charAt(String.java:686)

    at P43.main(P43.java:13)

    这是我的代码,用于查找大写字母并打印它们:

    import java.io.*;

    import java.util.*;

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

    //Uppercase

    String isUp = "";

    System.out.print("Please give a string: ");

    String x = in.next();

    int z = x.length();

    for(int y = 0; y <= z; y++){ if(Character.isUpperCase(x.charAt(y))){ char w = x.charAt(y);

    isUp = isUp + w + " ";

    }

    }

    System.out.println("The uppercase characters are " + isUp);

    //Uppercase

    }

    }

    2021-11-03 14:14:05
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载