Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:45:36+00:00 2026-05-25T20:45:36+00:00

Ok i have to pass a string to the main method which is obviously

  • 0

Ok i have to pass a string to the main method which is obviously stored in args[0].Then count the amount of times an uppercase letter occurs. For some reason i do not seem to be counting the uppercase occurrence properly. This is homework, any ideas? Thanks in advance.

package chapter_9;    

public class Nine_Fifteen {

    public static void main(String[] args) {
        int caps = 0;

        for(int i = 0;i < args.length;i++) {
            if (Character.isUpperCase(args[0].codePointCount(i, i))){
                    caps++; 
            }


        System.out.println("There are " + caps + " uppercase letters");

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:45:36+00:00Added an answer on May 25, 2026 at 8:45 pm

    The problem is your use of String.codePointCount:

    Returns the number of Unicode code points in the specified text range of this String. The text range begins at the specified beginIndex and extends to the char at index endIndex – 1. Thus the length (in chars) of the text range is endIndex-beginIndex. Unpaired surrogates within the text range count as one code point each.

    That’s not what you want – you’re passing that into Character.isUpperCase, which isn’t right.

    Do you definitely need to handle non-BMP Unicode? If not, your code can be a lot simpler if you use charAt(i) to get the char at a particular index instead. You also want to loop from 0 to args[0].length() as Kevin mentioned. I would suggest extracting the args[0] part to a separate string variable to start with, to avoid the confusion:

    String text = args[0];
    for (int i = 0; i < text.length(); i++) {
        // Check in here
    }
    

    I won’t complete the code for you as it’s homework, but hopefully this will be enough to get you going.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a flashobject which I need to pass a formatted DateTime string
I have the following scenario where I want to pass in string and a
I'm trying to pass a string to chdir(). But I always seem to have
If I have the value 0.0042 returned and I pass this to: string.Format({0:C},....); It
Let's say that I have this string: s = '<p>Hello!</p>' When I pass this
You have to pass the args variable to the anonymous function, but the anonymous
I have the following code which has a mutable Person class, String and a
I have the following code which draws a square on the main window of
Here's the situation. I have a base class which implements a method that accepts
I have a simple static method : public static <U> U findStuff(String id) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.