Wednesday, 10 July 2013

Decision Making

ASSIGNMENT 5: DECISION MAKING:

public class MyJavaProject {

    public static void main(String[] args) {
     int a = 4;
     int b = 10;
   
     if (a < b)
     {
         System.out.println("You are cool!");
     }
     else
     {
         System.out.println("You are idiot");
     }
     //******************************************
     if (a > b)
     {
         System.out.println("You are succeeded");
     }
     else
     {
         System.out.println("You are many times idiot");
     }
       
}


}

Exception - Try Catch

ASSIGNMENT 4: EXCEPTION, TRY-CATCH:

public class MyJavaProject {
   


    public static void main(String[] args) {
        int a = 4;
        int b = 0;
        int x = a / b;
        try
        {
            System.out.println("your value is divided");
            System.out.println(x);
        }
        catch(ArithmeticException ex)
        {
            System.out.println("You can't this value by zero");
        }
        // first priority is given to try, if it is possible to calculate. Otherwise an error will be caught.

}

Loops - Call Your Function many times

ASSIGNMENT 3: LOOPS - call your function many times: 
 
public class MyJavaProject {
   

    public static void main(String[] args) {
   
        for (int u = 0; u < 10; u++)

 // 0 < 10 (true); 0 + 1 = 2 (printed); and so on until value offs.
        {
            System.out.println(u);
         }

}
}

Basic Arithmetic


ASSIGNMENT 2: PRINT YOUR CALCULATED VALUE WITH A TEXT:

public class MyFirstProject {

 public static void main(String args[]){
        int a = 5;
        int b = 5;
        int x = a + b;
       
        System.out.println("Your Total sum is: => " + x); 

// Your Total sum is: => 1     
}
}



ASSIGNMENT 1: PRINT YOUR CALCULATED VALUE:
 
public class MyFirstProject {

 public static void main(String args[]){
        int a = 5;
        int b = 5;
        int x = a + b;
       
        System.out.println("x"); // OR;
        System.out.println(a + b);
        System.out.println(a - b);
        System.out.println(a * b);
        System.out.println(a / b);
        System.out.println(a % b); // Remainder (%)
}

}