0

From the command line i give values of the array:

> java program Hello HelloWorld "Hello World"

I need to count length of each value. I supposed to receive { 5 , 10 , 2 } but my code is couting each separate character in "Hello World" input instead of taking each word as a 1 string. How can I do so?

2
  • 2
    Please edit your question to show your code. Commented Nov 11, 2020 at 10:17
  • 3
    Well "Hello Word" is one string, why do you expect that to be different from the other parameters? If you want to count words you need to split that string into words in your code. Also, why are you supposed to get 5, 10 and 2? 5 and 10 look like the length of the strings, why should "Hello World" be treated differently?
    – Thomas
    Commented Nov 11, 2020 at 10:24

1 Answer 1

0

lets say your string is called Arr and already has the values inside- you can create a loop which goes through each spot of the array and you can check the length of the string. also, create a integer array lets call it ar - int[] ar= new ar[arr.length] which will contain the length of the strings values.

for(int i=0; i<Arr.length;i++){
    Ar[i]= arr[i].length();// or loop through the string value and use variable count to count the letters.
}

good luck. hope this works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.