2005/10/24

Lab Max-Min

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class labmaxmin {
public labmaxmin() {
}
public static void main(String[] args) throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a list of nonegative scores:");


double next, sum = 0,max = 0,min = 100;
int count = 0;
String nextstr = keyboard.readLine();
next = Double.parseDouble(nextstr);
while (next >= 0)
{

count++ ;
if (max <= next) max = next; else if (min >= next)
min = next;
nextstr = keyboard.readLine();
next = Double.parseDouble(nextstr);
}

if (count == 0 )
System.out.println("No score enteres");
else
{

System.out.println(count + " Scores read.");
System.out.println("Max is " + max );
System.out.println("Min is " + min );
}
}
}

0 Comments:

張貼留言

<< Home