Wednesday, December 30, 2015

Table of Powers Ex. 1.4

 1 //Print a table
 2 public class TableOfPowers{
 3    public static void main(String[] args){
 4       System.out.println("a    a^2   a^3");
 5       System.out.println("1    1     1");
 6       System.out.println("2    4     8");
 7       System.out.println("3    9     27");
 8       System.out.println("4    16    64");
 9    }//end main
10 }//end class

JAVA Pattern Ex. 1.3

1 //Display JAVA pattern
2 public class JavaPattern{
3    public static void main(String[] args){
4       System.out.println("   J     A    V     V    A");
5       System.out.println("   J    A A    V   V    A A");
6       System.out.println("J  J   AAAAA    V V    AAAAA");
7       System.out.println(" JJ   A     A    V    A     A");
8    }//end main method
9 }//end class

Welcome to Java Five Times Ex 1.2

 1 //Display message five times
 2 public class MessageFive{
 3    public static void main(String[] args){
 4       System.out.println("Welcome to Java!");
 5       System.out.println("Welcome to Java!");
 6       System.out.println("Welcome to Java!");
 7       System.out.println("Welcome to Java!");
 8       System.out.println("Welcome to Java!");
 9    }//end main
10 }//end class

Tuesday, December 29, 2015

Three Messages Ex. 1.1

//Display three messages
public class ThreeMessages {
       public static void main(String[] args) {
             System.out.println("Welcome to Java");
             System.out.println("Welcome to Computer Science");
             System.out.println("Programming is fun");
       }
}//end class




TABLE 1.2 Special Characters
Character/Name                               Description
{} Opening and closing braces                Denote a block to enclose statements.
() Opening and closing parentheses           Used with methods.
[] Opening and closing brackets              Denote an array.
// Double slashes                            Precede a comment line.
" " Opening and closing quotation marks      Enclose a string (i.e., sequence of                                                        characters).
; Semicolon                                  Mark the end of a statement.