154k views
5 votes
I need a help with java program which takes input

Routing 34 345 345 ( this is just example, instead of 34 345 345 it can be 347 234 456 etc )

this will split in spaces Routing will save in one array and 34 345 345 will split again by spaces. it will check the length and add all the indexes.

problem i am facing i am getting output
Routing 34

User Amwinter
by
8.4k points

1 Answer

4 votes

Final answer:

The solution involves splitting the input string and then summing the numeric parts after converting them to integers. Java's String.split() method will be instrumental in resolving the issue.

Step-by-step explanation:

The Java program in question is designed to take a string input such as "Routing 34 345 345", split this input into parts, and perform some operations on the numeric parts of the input. The student wants the first word, 'Routing', to be saved in one array, while the numerical parts, like '34 345 345', are to be split by spaces, added together, and possibly perform some additional operations based on the length of these numbers.

To accomplish this, you can use Java's String.split() method to separate the string into parts. Firstly, you would split the input string into two parts: 'Routing' and '34 345 345'. The 'Routing' part can be stored in a simple string variable. Then, split the second part by spaces to obtain each number separately. Finally, you can convert these strings into integers and sum them up using a loop.


User Cal McLean
by
8.1k points