



|
|
CS1 Course Site
|
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )
Monday October 23 , 2000
|
|
Program 1
/ /Read and echo two integers
int a = IO.read_int ();
int b = IO.read_int ();
IO.println ( ``a = ``+ a);
IO.println ( ``b = ``+ b);
}
Program 2 static ---------
{
/ /Same as P1
-------------
-------------
-------------
/ /Computer and print the maximum value
int max = max (a, b);
IO.println (max);
}
static private int max (int a, int b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
Program 3 static --------
{
P1 Stuff
-------------
-------------
-------------
P2 Stuff
-------------
-------------
-------------
P3 compute min value
int min = min (a, b);
IO.println ( ``min = ``+ min);
{
max
min
Program 4 statix ----------
{
/ /P1
-------------
-------------
-------------
/ /P2
-------------
-------------
-------------
/ /P3
-------------
-------------
-------------
/ /Compute and display the difference
int diff = max - min;
IO.println ( ``diff = ``+ diff);
}
Program 5 (Final version)
Simply delete all output statements other than the final output statement.
Problem
Read several (at least one) non negative integers and compute their real average.
< PROGRM >
/ /Establish an accumulator
int sum = 0;
/ /Establish a counter to count data
int count = 0;
/ /sum the integers
int num = IO.read_int ();
while (num > = 0)
{
sum = sum + num
count = count + 1; / /count + +
num = IO.read_int ();
}
/ /Compute + Display the average
double ave = (double) sum / (double) count;
IO.println ( ``ave = ``+ ave);
}
Problem
Read several non zero integers and display the largest.
Ex
in:10, 7, 95, 4, 66, 0
out:95
in: - 10, - 7, - 95, - 4, - 66, 0
out: - 4
|
|