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?
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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.