Pages

Tutorials

 Java Programming Tutorial - 1
 Code :

class mks{
  public static void main(String[] args){
 
    System.out.println("Hello Java");

}  
}

Output :

Hello Java

 Java Programming Tutorial - 2
 Code :

class mks{
  public static void main(String[] args){
  
  int friends;
  friends = 13;
    
     System.out.print("I have ");
     System.out.print( friends );
     System.out.println(" friends.");

}  
}

Output :

I have 13 friends.

 Java Programming Tutorial - 3
 Code :

import java.util.Scanner;
class mks{
  public static void main(String[] args){
  
  Scanner mark = new Scanner (System.in);
  System.out.println( mark.nextLine() );
   
}  
}

Output :
98       //User Input Value
98

Java Programming Tutorial - 4
 Code :

import java.util.Scanner;
class mks{
  public static void main(String[] args){
Scanner mark = new Scanner (System.in);   
double num1, num2, answer;
    System.out.println( "Insert First Number  :  " );
    num1=mark.nextDouble();
    System.out.println( "Insert Second Number  :  " );
    num2=mark.nextDouble();
    answer = num1 + num2 ;
     System.out.println( "num1 + num2 : " +answer );
    answer = num1 - num2 ;
     System.out.println( "num1 - num2 :" +answer );
    answer = num1 * num2 ;
     System.out.println( "num1* num2 :" +answer );
    answer = num1 / num2 ;
     System.out.println( "num1 / num2  : " +answer );
    answer = num1 % num2 ;
     System.out.println( "num1 % num2 : " +answer );
}  
}

Output :

Insert First Number  : 
55
Insert Second Number  : 
10
num1  +  num2 : 65.0
num1  -   num2 :45.0
num1  *   num2 :550.0
num1   /   num2  : 5.5
num1  %  num2 : 5.0

Java Programming Tutorial - 5
 Code :

class mks{
  public static void main(String[] args){

int X =20;
int Y =20;
int S =20;
int P =20;
System.out.println( ++X );
System.out.println( Y++ );
System.out.println(  --S  );
System.out.println(  P--  ); 
int A =20;
int B =20;
int C =20;
int D =20; 
System.out.println(  A+=5 );
System.out.println(  B-=5  );
System.out.println(  C/=5  );
System.out.println(  D*=5 );


  
}  
}

Output :

21
20
19
20
25
15
4
100

 Java Programming Tutorial - 6
 Code :

class mks{
  public static void main(String[] args){

  int marks = 98;        // Value of marks variable
   
  if(marks <= 45){
        System.out.println("Fail");
     }else if( marks >=46 && marks <= 55){
        System.out.println("C");
     }else if( marks >=56 && marks <= 65){
        System.out.println("B");
     }else if( marks >=66 && marks <= 75){
        System.out.println("A");
     }else if( marks >=90 && marks <= 100){
        System.out.println("A+");
     }else{
        System.out.println("Invalied Marks");
     }

}  
}

Output :
A+
 

  • && means AND Operator.It checks all the arguments and if all arguments are true it is going inside.
  • || means OR Operator.It checks all the arguments.Even if one argument is true it is going inside.
  • != means NOT Operator.
  • == means Equal Operator.It checks the equality.

 Java Programming Tutorial - 7
 Code :

class mks{
  public static void main(String[] args){

     int marks = 4;

      switch(marks){
         case 1:
           System.out.println("Funny");
           break;
         case 2:
           System.out.println("Sad");
           break;
         case 3:
           System.out.println("Good");
           break;
         case 4:
           System.out.println("Angrey");
           break;
         default:
           System.out.println("I don't understand your mood");
           break;
     }

}  
}

Output :
Angrey