0% found this document useful (0 votes)
60 views7 pages

Nested Loop Quiz & Number To Words

The document combines two Java programs, Nested Loop Quiz and Number to Words, into one file for easier grading. The Nested Loop Quiz program uses loops to display even and odd numbers up to a user-input number. The Number to Words program converts a user-input number between 0-9999 into words. The programmer wishes the reviewer a Merry Christmas and Happy New Year.

Uploaded by

Kem Kem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views7 pages

Nested Loop Quiz & Number To Words

The document combines two Java programs, Nested Loop Quiz and Number to Words, into one file for easier grading. The Nested Loop Quiz program uses loops to display even and odd numbers up to a user-input number. The Number to Words program converts a user-input number between 0-9999 into words. The programmer wishes the reviewer a Merry Christmas and Happy New Year.

Uploaded by

Kem Kem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Dear Ma’am,

Pinagsama ko na po yung dalawang files (Nested Loop Quiz at Number to Words) para madalian
po kayo sa checking. Merry Christmas and Happy New Year po.

Nested Loop Quiz


import javax.swing.JOptionPane;

public class OddOrEven {


public static void main(String [] args) {

String blengbong = "yes";


while(blengbong.equalsIgnoreCase("yes")) {
int n;

n = Integer.parseInt(JOptionPane.showInputDialog("Enter a number"));
int countEVEN =0;
String displayEVEN=" ";
while ( countEVEN <= n )
{ displayEVEN+=" " + countEVEN;
countEVEN+=2 ;
}
int count = 1 ;
String display=" ";

while ( count <= n )


{ display+=" " + count;
count+=2 ;
}
JOptionPane.showMessageDialog(null, "You entered " + n + "\n"
+ "Even Numbers:" + displayEVEN + "\n"
+ "Odd Numbers:" + display,
"Odd Even",JOptionPane.INFORMATION_MESSAGE);

blengbong = JOptionPane.showInputDialog("Run Again [Yes/ No]");

} //end of while

}
}

OUTPUT
Number to Words

import javax.swing.JOptionPane;

public class NumbersToWords {


public static void main(String[] args){
int enter, thou, hun, tens, ones, temp1, temp2;
String display="", input="yes";
while(input.equalsIgnoreCase("yes")) {
enter = Integer.parseInt(JOptionPane.showInputDialog("Enter a number from
[0-9999]"));

thou = enter/1000;
temp1= enter%1000;

switch(thou) {
case 9: display+=" Nine Thousand"; break;
case 8: display+=" Eight Thousand"; break;
case 7: display+=" Seven Thousand"; break;
case 6: display+=" Six Thousand"; break;
case 5: display+=" Five Thousand"; break;
case 4: display+=" Four Thousand"; break;
case 3: display+=" Three Thousand"; break;
case 2: display+=" Two Thousand"; break;
case 1: display+=" One Thousand"; break;
default: display+=""; break;
}

hun = temp1/100;
temp2 = temp1%100;
tens = temp2/10;
ones = temp2%10;
switch(hun) {
case 9: display+=" Nine Hundred"; break;
case 8: display+=" Eight Hundred"; break;
case 7: display+=" Seven Hundred"; break;
case 6: display+=" Six Hundred"; break;
case 5: display+=" Five Hundred"; break;
case 4: display+=" Four Hundred"; break;
case 3: display+=" Three Hundred"; break;
case 2: display+=" Two Hundred"; break;
case 1: display+=" One Hundred"; break;
default: display+=""; break;
}

if (tens!=1){ //if the tens place is not 1


switch(tens) {
case 9: display+=" Ninety"; break;
case 8: display+=" Eighty"; break;
case 7: display+=" Seventy"; break;
case 6: display+=" Sixty"; break;
case 5: display+=" Fifty"; break;
case 4: display+=" Forty"; break;
case 3: display+=" Thirty"; break;
case 2: display+=" Twenty"; break;
default: break;
}

switch(ones) {
case 9: display+=" Nine"; break;
case 8: display+=" Eight"; break;
case 7: display+=" Seven"; break;
case 6: display+=" Six"; break;
case 5: display+=" Five"; break;
case 4: display+=" Four"; break;
case 3: display+=" Three"; break;
case 2: display+=" Two"; break;
case 1: display+=" One"; break;
default: display+=""; break;
}
} else{ // if the tens value is equal to 1

switch(ones) {
case 9: display+=" Nineteen"; break;
case 8: display+=" Eighteen"; break;
case 7: display+=" Seventeen"; break;
case 6: display+=" Sixteen"; break;
case 5: display+=" Fifteen"; break;
case 4: display+=" Fourteen"; break;
case 3: display+=" Thirteen"; break;
case 2: display+=" Twelve"; break;
case 1: display+=" Eleven"; break;
default:display+=" Ten"; break;
}
}

JOptionPane.showMessageDialog(null,display,"Number to
Words",JOptionPane.INFORMATION_MESSAGE);

input = JOptionPane.showInputDialog("Again [Yes/No]");

}
}
}

You might also like