Escolar Documentos
Profissional Documentos
Cultura Documentos
java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, July 26, 2007, 11:10:50 AM
Description: This program uses array
Output: Multiplying a number to itself with out using input
stream reader
Program:
Program:
import java.io.*;
for(int x=0;x<A.length;++x){
B[x] = A[x] * A[x];
System.out.println(B[x]);
}
}
}
File Name: Array3.java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, June 21, 2007, 1:23:23 PM
Description: This program combined InputStreamReader and
BufferedReader in one line
Output: multiplying a number to itself
Program:
import java.io.*;
for(int x=0;x<A.length;++x){
B[x] = A[x] * A[x];
System.out.println(B[x]);
}
}
}
File Name: SwitchTest.java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, July 05, 2007, 1:04:22 PM
Description:
Output: Displaying a number
Program:
int KeyValue = 1;
switch(KeyValue){
case 1:
System.out.println("one");
break;
case 2:
System.out.println("two");
break;
case 3:
System.out.println("three");
break;
default:
System.out.println("more");
break;
}
}
}
File Name: Sample.java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, July 05, 2007, 1:04:22 PM
Description: This program uses two sub-class to diplay a
message
Output:
Program:
Program:
String[] month =
{"January","February","March","April"};
for(int i = 0;i<month.length;++i){
System.out.println(month[i]);
}
}
}
File Name: Month2.java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, June 28, 2007, 11:53:38 AM
Description:
Output:
Program:
Program:
import java.io.*;
System.out.println(output);
}
}
File Name: Kamikuto1.java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, July 05, 2007, 1:44:01 PM
Description: This program uses Switch Statements and
Multiple Sub-Classes to covert numbers to words
Output: Converting numbers to words
Program:
case 1:
return DefinePlace.UNITS;
case 2:
return DefinePlace.TENS;
case 3:
return DefinePlace.HUNDREDS;
case 4:
return DefinePlace.THOUSANDS;
case 5:
return DefinePlace.TENTHOUSANDS;
case 6:
return DefinePlace.MILLIONS;
//return DefinePlace.LAKHS;
case 7:
return DefinePlace.TENMILLIONS;
//return DefinePlace.TENLAKHS;
case 8:
return DefinePlace.BILLIONS;
//return DefinePlace.CRORES;
case 9:
return DefinePlace.TENBILLIONS;
//return DefinePlace.TENCRORES;
}//switch
return 0.0;
}// getPlace
return cleanedNumber;
} //cleanNumber
}//if
else if( place == DefinePlace.TENMILLIONS ){
num -= subNum * DefinePlace.MILLIONS;
returnValue += " Million ";
}//if
else if( place == DefinePlace.TENBILLIONS ){
num -= subNum * DefinePlace.BILLIONS;
returnValue += " Billion ";
//}//if
//else if( place == DefinePlace.TENLAKHS ){
//num -= subNum * DefinePlace.LAKHS;
//returnValue += " Lakhs ";
//}//if
//else if( place == DefinePlace.TENCRORES ){
//num -= subNum * DefinePlace.CRORES;
//returnValue += " Crores ";
}//if
}//if
else{
int subNum = Integer.parseInt( "" + number.charAt(0) );
}//if
else if( place == DefinePlace.MILLIONS ){
num -= subNum * DefinePlace.MILLIONS;
returnValue += " Million ";
}//if
else if( place == DefinePlace.BILLIONS ){
num -= subNum * DefinePlace.BILLIONS;
returnValue += " Billion ";
//}//if
//else if( place == DefinePlace.LAKHS ){
//num -= subNum * DefinePlace.LAKHS;
//returnValue += " Lakh ";
//}//if
//else if( place == DefinePlace.CRORES ){
//num -= subNum * DefinePlace.CRORES;
//returnValue += " Crore ";
}//if
}//else
}//while
return returnValue;
}//convert number
Program:
Program:
Program:
Program:
Program:
Program:
Program:
Program:
Program:
Program:
import javax.swing.*;
JOptionPane.showMessageDialog(null,message,"While
Loop",
JOptionPane.INFORMATION
_MESSAGE);
double total=0;
int count=1;
String msg=null;
while(count <= MAXNUM){
switch(count){
case 1:
msg = "First";
break;
case 2:
msg = "Second";
break;
case 3:
msg = "Third";
break;
case 4:
msg = "Fourth";
break;
}
total +=num;
++count;
}
JOptionPane.showMessageDialog(null,"The total of the
" + MAXNUM + " numbers is " + total,
"Result",JOptionPane.IN
FORMATION_MESSAGE);
System.exit(0);
}
}
File Name: Kuto.java
Terminal No: 9
Programmer: Delos Reyes, Jose Mari Luis C.
Date and Time Created: Thursday, August 02, 2007, 11:05:42
AM
Description:
Output:
Program:
What is Inheritance?
(For Volume1.java)
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
(For Volume1.java)
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
(For Switchtest.java)
(For While.java)
while (true){
// your code goes here
}
do {
statement(s)
} while (expression);
The difference between do-while and while is that do-while
evaluates its expression at the bottom of the loop instead
of the top. Therefore, the statements within the do block
are always executed at least once, as shown in the
following DoWhileDemo program:
class DoWhileDemo {
public static void main(String[] args){
int count = 1;
do {
System.out.println("Count is: " + count);
count++;
} while (count <= 11);
}
}