public class javapractice14
{
public static void main(String[] args)
{
int largest = Integer.MIN_VALUE;
int smallest = Integer.MAX_VALUE;
Scanner console = new Scanner(System.in);
System.out.println("Please enter desired amount of numbers (-1 ends program)");
for( int number = console.nextInt(); number != -1; number = console.nextInt()); //Enter -1 to end program
{
我在下面收到我的错误,说它找不到符号:变量号
我相信 number 是在 for 循环中声明的,不是在那里声明的吗?我尝试在循环外声明“ int number; ”,但结果相同。我用过:我必须怎么做才能使用循环显示最大和最小的数字?作为帮助我解决部分问题的参考。
largest = number > largest ? number : largest;
smallest = number < smallest ? number : smallest;
}
System.out.println("Your largest number is: " + largest);
System.out.println("You smallest number is: " + smallest);
}
}