print "there are "
when napples
= 2: print "a couple"
= 3: print "a few"
= 4, 5: print "several"
> 5: print "many"
print " apples in the crate"
System.out.println("there are ");
if ( napples == 2 )
System.out.println("a couple");
else if ( napples == 3 )
System.out.println("a few");
else if ( napples == 4 || napples == 5 )
System.out.println("several");
else
System.out.println("many");
System.out.println(" apples in the crate.");
System.out.println("there are ");
switch ( napples )
{
case 2:
System.out.println("a couple");
break;
case 3:
System.out.println("a few");
break;
case 4:
case 5:
System.out.println("several");
break;
default:
System.out.println("many");
}
System.out.println(" apples in the crate.");
more_employees <- true while more_employees do read hours worked print pay ($6.50 per hour with no overtime pay) ask if want to process more employees
public static void main(String[] args)
{
final double HOURLY_PAY = 6.50;
double hours;
boolean more_employees = true; // assume at least 1 employee
while ( more_employees )
{
System.out.print("Enter hours worked for next employee: ");
hours = in.nextDouble();
System.out.println("Pay: " + hours * HOURLY_PAY);
System.out.print("Do you have more employees to pay? ");
char resp = in.nextChar();
more_employees = resp == 'y' || resp == 'Y';
}
}
initialize while event not satisfied process check event
int char_count = 0, num_periods = 0;
while ( num_periods < 5 )
{
char ch = in.nextChar();
char_count++;
if ( ch == '.' )
num_periods++;
}
int sum = 0;
int count = 0;
while ( sum < 1000 )
{
int num = nextInt();
sum = sum + num;
count++;
}
System.out.println("Number of numbers: " + count);
read target
read guess
count = 1
while guess != target
count++
read guess
print count
3 number of teams
A 130 112 143 -1 team A (3 players)
B -1 team B (0 players!)
C 180 201 145 115 -1 team C (4 players)
A 780 519 341 112 -1
B -1
C 1115 13 20 -1
if ( n != 0 && sum / n > 20 ) ...
what would happen in n was 0?
if ( n == 0 || pow(pow(n, 0.5), n) > 200.0 ) ...