作業3/13-2
程式碼
package s9325116;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class s9325116{
public s9325116(){
}
public static void main(String[] args)throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter some nonnegative numbers:");
System.out.println("Mark the end with a negaive number.");
System.out.println("I will compare Max and min");
double max=-1,min=-1,num=0;
int count=0;
String input="";
while(num >= 0)
{
input = keyboard.readLine();
num = Double.parseDouble(input);
if ((max==-1)||(num>=max)&&num>=0)
max = num;
if((min==-1)||(num<=min)&&num>=0)
min = num;
count++;
}
if (count==0)
System.out.println("No numbers entered.");
else
{
System.out.println("There are "+count+" numbers read.");
System.out.println("The max is "+max+" and the min is "+min);
}
}
}
0 Comments:
发表评论
<< Home