Information Technology Reference
In-Depth Information
Table 8.2 (continued)
System.out.println(“license”);
}
}
The typed number
Is “license”printed?
import java.util.Scanner;
public class License {
public static Scanner input = new
Scanner(System.in);
public static void main(String[] args) {
double age;
System.out.println(“enter age”);
age = input.nextDouble();
if (age>=17)
System.out.println(“license”);
else
System.out.println(“no license”);
Task 3, Part B
We now expand the conditional statement so that if
the age is not bigger or equal 17, “no license”is
printed.
Change it and save it.
Run it three times. Each time, type a different input
and fill in the following table:
}
}
The typed number
The printed message
Intermediate summary:
The statement
if (age> = 17)
System.out.println(“license”);
else
System.out.println(“no license”);
is an extended conditional statement.
Its general structure is:
if (a condition)
an instruction for execution;
else
an instruction for execution;
Task 4
Write a program that prints the bigger number from two given numbers.
Type it, save it, and check that you get the expected output.
import java.util.Scanner;
public class Check5 {
public static Scanner input = new
Scanner(System.in);
public static void main(String[] args) {
double x, y;
System.out.println(“enter two numbers”);
x = input.nextDouble();
y = input.nextDouble();
if (x < y)
System.out.println(“hello”);
Task 5
Type the given class.
The left column of the table below includes
differentconditions.
Run the class 6 times. Each time,change the
condition (x < y) with one of the conditions
presented in the table, and fill in the table.
}
}
The condition
x < y
x <= y
x > y
x >= y
The sign
<
<=
>
>=
Itsmeaning
Smaller than
Bigger or equal
Search WWH ::




Custom Search