Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, Here is the program I\'m trying to work on: (Finding the number of upperc

ID: 3630115 • Letter: H

Question

Hello,

Here is the program I'm trying to work on:

(Finding the number of uppercase letters in a string) Write a program that passes a string to the main method and displays the number of uppercase letters in a string.

Here is the code I have so far:

public class CountUppercase {


public static void main(String[] args) {


int count = 0;
String str = args[0];
for(int i=0;i<str.length();i++)
if(str.charAt(i)>64 && str.charAt(i)<91)
count++;

System.out.println("total upper characters in string" + str + "are" + count);
}
}

I'm getting the following errors in NetBeans:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at countuppercase.CountUppercase.main(CountUppercase.java:16)
Java Result: 1

Where am I going wrong?

Explanation / Answer

u have to give command line arguments

compile your code and

run through command winodw as follows.

java <java_class_name> aswaniKUMA

or in net beans given commnad line argument as string that u wanted to pass.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote