我最后想要我的输出,但我的程序在每次输入后都会给出它。请告诉我应该做哪些改变!我的程序从最多十个数字中整理出用户输入的所有负数。我的程序是:
import java.io.*;
public class Task_3
{
public static void main(String args[])throws IOException
{
double a, b;
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(read);
for(a=1;a<=10;a++)
{
System.out.println("Enter your number");
b=Double.parseDouble(in.readLine());
if(b<0)
{
System.out.println(b);
}
}
}
}
结果显示在输出屏幕上:
Enter your number
5
Enter your number
6
Enter your number
1
Enter your number
45
Enter your number
874
Enter your number
-547
-547.0
Enter your number
-8
-8.0
Enter your number
-1
-1.0
Enter your number
-5
-5.0
Enter your number
6