by
PRO
FE S
S OR

QUIZ for SECTION VII
To find an answer, click on the desired question.
QUESTION 1:
Follow the Leap year algorithm:
QUESTION 2:
QUESTION 3:
QUESTION 4:
QUESTION 5:
QUESTION 6:
ANSWER to QUESTION 1:
{
{
System.out.print("Enter a year : ");
int year = Input.enterInt(); // Input.class needed to enter an 'int'
if (year%400==0)
if (leapYear)
This program requires Input.class in same directory to enter an 'int'.
Use right mouse button and click on Input.class to download it.
If you do not want to use the Input.class to enter the 'int' value from the keyboard, you can hard code it:
int year = < a_year > ;
ANSWER to QUESTION 2:
{
{
char letter = 'A'; // beginning character
for (int i=0; i < alphabet.length; i++)
{
// for loop above populates the alphabet.
for (int i=0; i < alphabet.length; i++)
{
// for loop above is to display each character of the alphabet.
We could have had only one for loop, if we include the display method with the first for loop.
ANSWER to QUESTION 3:
{
{
System.out.print("Enter an alphabet letter (A through Z : ");
char letter = Input.enterChar(); // Input.class needed to enter a 'char'
switch(letter)
{
case 'E':
case 'I':
case 'O':
case 'U':
break;
break;
if (vowel)
This program requires Input.class in same directory to enter a 'char'.
Use right mouse button and click on Input.class to download it.
When executing this program, make certain you enter your vowels upper case as it would interpret the lower case
letters as consonants.
If you do not want to use the Input.class to enter the 'char' from the keyboard, you can hard code it: char letter = < a_letter >;
ANSWER to QUESTION 4:
ANSWER to QUESTION 5:
{
{
while(j>1)
{
if (j==6)
ANSWER to QUESTION 6:
{
{
System.out.print("Enter 1st integer: ");
int a = Input.enterInt();
System.out.print("Enter 2nd integer: ");
int b = Input.enterInt();
System.out.print("Enter 3rd integer: ");
int c = Input.enterInt();
// Integers a, b, c, will be placed in ascending order into integers x, y, z.
if (a >= b && a >= c)
{
if ( b > c)
{
y = b ;
else
{
y = c ;
if ( b >= a && b >= c)
{
if ( a > c)
{
y = a ;
else
{
y = c ;
if ( c >= a && c >= b )
{
if ( a > b)
{
y = a ;
else
{
y = b ;
System.out.print("Integers in ascending order are: " + x + " " + y + " " + z);
This program requires Input.class in same directory to enter the integers.
Use right mouse button and click on Input.class to download it.
Algorithm used above is not the bubble sort. Bubble sort is a popular method that can be used to arrange numbers in ascending
or descending order.
If you do not want to use the Input.class to enter the integers from the keyboard, you can hard code them:
int a = < a_value >; , int b = < a_value > ; , and int c = < a_value > ;