Answer the question
In order to leave comments, you need to log in
A method that will accept text as input and return an array of int[](Error handling)?
Help me find where my mistake is:
Write a method that will accept text as input and return an int[] array of all the numbers that it contains.
For each word that is not an integer, print “not a number” to the console on a new line.
ps I understand that the task is specifically for the topic of error handling, because in the condition the text and you need to return an array of numbers
and the catch is that I don’t understand how to transfer the text to an ARRAY of ints
public int[] findNumbers(String text){
String[]str=text.split(" ");
int[] numbers=new int[str.length]; //тут требует инт а у меня массив интов
try {
return Integer.parseInt(text);
}catch (Exception e){
System.out.println("not a number");
}
return numbers;
}
Answer the question
In order to leave comments, you need to log in
It is necessary to go through all the elements of the str array, try to steam each of them, and add them to the array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question