Помните, что вы не узнаете ничего от того, чтобы ваше домашнее задание сделано людьми онлайн. Вы можете чему-то научиться у него в любом случае и попробовать себя в следующий раз. Я включил комментарии в решение.
public static void main(String[] args) {
//The line is a String, and the numbers must be parsed to integers
String line = "564 33 654 8321 15";
//We split the line at each space, so we can separate each number
String[] array = line.split("\\s+");
//Integer.MIN_VALUE will give you the smallest number an integer can have,
//and you can use this to check against.
int largestInt = Integer.MIN_VALUE;
//We iterate over each of the separated numbers (they are still Strings)
for (String numberAsString : array) {
//Integer.parseInt will parse a number to integer from a String
//You will get a NumberFormatException if the String can not be parsed
int number = Integer.parseInt(numberAsString);
//Check if the parsed number is greater than the largestInt variable
//If it is, set the largestInt variable to the number parsed
if (number > largestInt) {
largestInt = number;
}
}
//We are done with the loop, and can now print out the largest number.
System.out.println(largestInt);
}
Можете ли вы показать нам, что вы уже пробовали, и почему он не работает, а не просто псевдокод –
Я согласен с peeskillet здесь. У вас уже есть псевдокод (это очень хороший старт). Если вы на самом деле не ввели его в код, запустите один шаг за раз, например, просто извлеките номера из строки для начала. Возможность разбить программу на небольшие, управляемые части - очень важный навык, поэтому многие из нас не размещают решения; это лишит вас важного опыта. –
Я просто хочу знать, как получить доступ к каждому номеру в строке? –