Wednesday, September 17, 2008

Coding done in class September 17th, 2008

public class HelloWorld //class designed to print hello world!
{
public static void main(String [] args)
{ //main method needed to run java application
System.out.println("Hello World!");
//syntax to print "Hello World!"
//while loop
//for loop
int counter = 0;
while(counter <= 10)
{
System.out.println(counter);
counter += 2; //the shortcut for counter = counter + 2;
}

for(int i = 100; i > 0; i --)
{
System.out.println(i);
if(i % 25 == 0){
System.out.println(i + " THIS IS A SPECIAL NUMBER!");
}

}

for(int i = 200; i > 0; i --)
{
//System.out.println(i);
if(i % 3 == 0 || i % 7 ==0 ){
System.out.println(i + " THIS IS A SPECIAL NUMBER 3 and 7");
}

}

} //Closing curly brackets /* hello */


} //closing curly brackets

1. Write a program to display "Hello World"
2. Write a program that loops to ten from 0 by 2 and prints out the result!
3. Add a for loop that counts down from 100 to 0 by one! Print out the results!
4. Within the previous loop, if a number is divisible by 25 evenly
output THIS IS A SPECIAL NUMBER!! %
5. Count down from 200 by 1 and find out if a number is divisible evenly by 3 and 7 together.
If it is print out a message "This number is divisible by 3 and 7!"
6. Start Netbeans and make a class for a student. Keep track of the GPA and Name. Provide getters,
setters, and a constructor! Call this class student.
7. Test program with main method by passing in a student
named "Jose" with a GPA of 3.5.
8. Make an array of 4 students and give them whatever info you like.
9. Print out the information in the array!
10. Ask user to enter a student name and GPA and make a student object!

No comments: