Followers

Wednesday, 14 December 2016

JAVA CRASH COURSE

/*-----------------------------------------------------------------------------------------------------------------------------
1] STAR PATTERN 1

 *  *  *  *
 *  *  *  *
 *  *  *  *
 *  *  *  *
--------------------------------------------------------------------------------------------------------------------------------*/

import java.io.*;

class pattern1
{
    public static void main(String args[])
    {
        int i,j;
       
        for(i=0;i<4;i++)
        {
            for(j=0;j<4;j++)
            {
                System.out.print(" * ");
            }
            System.out.print("\n");
           
        }
    }
   
}

/******************************OUTPUT*************************************
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac pattern1.java
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java pattern1
 *  *  *  *
 *  *  *  *
 *  *  *  *
 *  *  *  *
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

-------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------
2] NUMBER PATTERN 1

 1  2  3  4
 1  2  3  4
 1  2  3  4
 1  2  3  4
--------------------------------------------------------------------------------------------------------------------------------*/
import java.io.*;

class pattern2
{
    public static void main(String args[])
    {
        int i,j;
       
        for(i=1;i<=4;i++)
        {
            for(j=1;j<=4;j++)
            {
                System.out.print(" "+j+" ");
            }
            System.out.print("\n");
           
        }
    }
   
}

/*----------------------------OUTPUT-----------------------------------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac pattern2.java
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java pattern2
 1  2  3  4
 1  2  3  4
 1  2  3  4
 1  2  3  4
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
3] Accept no from user and print its table
---------------------------------------------------------------------------------------------------------------------------------*/

import java.io.*;

class table
{
    public static void main(String args[]) throws IOException
    {
        int a,i;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter the number :");
        a=Integer.parseInt(in.readLine());
       
        for(i=1;i<=10;i++)
        {
            System.out.println(a+ " X " +i+ " = " +a*i);
        }
       
    }
}

/*---------------------------------OUTPUT-------------------------------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac table.java
Note: table.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java table
Enter the number :34
34 X 1 = 34
34 X 2 = 68
34 X 3 = 102
34 X 4 = 136
34 X 5 = 170
34 X 6 = 204
34 X 7 = 238
34 X 8 = 272
34 X 9 = 306
34 X 10 = 340
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$


--------------------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
4] Calculator program using java
----------------------------------------------------------------------------------------------------------------------------------*/
import java.io.*;

class calc
{
    public static void main (String args[]) throws IOException
    {
        int a,b,res, ch;
        DataInputStream in =new DataInputStream(System.in);
       
        System.out.print("Enter a :");
        a=Integer.parseInt(in.readLine());
       
        System.out.print("Enter b :");
        b=Integer.parseInt(in.readLine());
       
        do
        {
            System.out.println("\n1.Add");
            System.out.println("2.Subtract");
            System.out.println("3.Multiply");
            System.out.println("4.Divide");
            System.out.println("5.Exit");
       
           
            System.out.println("\nEnter your choice");
            ch=Integer.parseInt(in.readLine());
       
            switch (ch)
            {
                case 1:
                    res=a+b;
                    System.out.println("Addition is " +res);
                    break;
                case 2:
                    res=a-b;
                    System.out.println("Subtraction is " +res);
                    break;
                case 3:
                    res=a*b;
                    System.out.println("Multiplication is " +res);
                    break;
                case 4:
                    res=a/b;
                    System.out.println("Division is " +res);
                    break;
                case 5:
                    System.out.println("Exit");
                    break;
               
            }   
        }while(ch!=4);
    }
}


/*-----------------------------------------------OUTPUT------------------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac calc.java
Note: calc.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java calc
Enter a :2
Enter b :5

1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit

Enter your choice
1
Addition is 7

1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit

Enter your choice
2
Subtraction is -3

1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit

Enter your choice
3
Multiplication is 10

1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit

Enter your choice
4
Division is 0
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$
--------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
5] Accept array and print using functions using java
------------------------------------------------------------------------------*/
import java.io.*;

class array
{
    DataInputStream in=new DataInputStream(System.in);
    int i;
    int a[]=new int [5];
    void accept() throws IOException
    {
        System.out.println("Enter element");
        for(i=0;i<5;i++)
        {
           
            a[i]=Integer.parseInt(in.readLine());
        }
       
    }
   
    void disp()
    {
        for(i=0;i<5;i++)
        {
            System.out.print(" "+a[i]+" ");
        }
    }
   
    public static void main(String args[]) throws IOException
    {
        DataInputStream in=new DataInputStream(System.in);
        int ch;
        array a=new array();
        do
        {
            System.out.println("\n*********MENU*********");
            System.out.println("1.Accept");   
            System.out.println("2.Disp");
            System.out.println("3.Exit");   

            System.out.println("\nEnter your choice");
            ch=Integer.parseInt(in.readLine());
       
       
            switch (ch)
            {
                case 1 :
                    a.accept();
                    break;
                case 2 :
                    a.disp();
                    break;
                case 3 :
                    System.out.println("Exit");
                    break;
            }
        }while(ch!=4);
               
    }
}

/*---------------------------------------------------------OUTPUT-----------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac array.java
Note: array.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java array

*********MENU*********
1.Accept
2.Disp
3.Exit

Enter your choice
1
Enter element
1
2
3
2
3

*********MENU*********
1.Accept
2.Disp
3.Exit

Enter your choice
2
 1  2  3  2  3
*********MENU*********
1.Accept
2.Disp
3.Exit

Enter your choice
3
Exit

*********MENU*********
1.Accept
2.Disp
3.Exit

Enter your choice
4
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$
----------------------------------------------------------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------------------------------------------
6] Even odd check using java
-----------------------------------------------------------------------------------------------------------------------*/


import java.io.*;

class even
{
    public static void main(String args[]) throws IOException
    {
        int a;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter the number :");
        a=Integer.parseInt(in.readLine());
       
        if(a%2==0)
        {
            System.out.println(a+" is even number");
        }
        else
            System.out.println(a+" is odd number");
       
    }
}

/******************OUTPUT********************************************
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac even.java
Note: even.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java even
Enter the number :45
45 is odd number
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

--------------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
7] Check greater no using java
----------------------------------------------------------------------------------------------------------------------------- */
import java.io.*;

class greater
{
    public static void main(String args[]) throws IOException
    {
        int num1,num2;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter the first no :");
        num1=Integer.parseInt(in.readLine());
       
        System.out.print("Enter the second no :");
        num2=Integer.parseInt(in.readLine());
       
        if(num1>num2)
        {
            System.out.println(num1+ " is greater than "+num2);
        }
        else if(num1<num2)
        {
            System.out.println(num2+ " is greater than "+num1);
        }
        else
        {
            System.out.println("Both are equal ");
        }
    }
   
}

/*---------------------------------------------------OUTPUT-----------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac greater.java
Note: greater.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java greater
Enter the first no :45
Enter the second no :32
45 is greater than 32
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

--------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
8] Accept number from user and check whether it is palindrome or not
-----------------------------------------------------------------------------------------------------------------------------------*/
import java.io.*;

class palindrome
{
    public static void main(String args[]) throws IOException
    {
        int a,re=0,temp;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter the number :");
        a=Integer.parseInt(in.readLine());
       
        temp=a;
        while(temp!=0)
        {
            re=re*10;
            re=re+(temp%10);
            temp=temp/10;
        }
        if(a==re)
        {
            System.out.println("It is palindrome");
        }
       
        else
        {
            System.out.println("Non palindrome");
        }
    }
}

/*----------------------------------------------------OUTPUT-----------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac palindrome.java
Note: palindrome.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java palindrome
Enter the number :12344321
It is palindrome
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$


--------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
9] Check whether entered no is prime or not using java
--------------------------------------------------------------------------------------------------------------------------------*/
import java.io.*;

class prime
{
    public static void main(String args[]) throws IOException
    {
        int a,i,num,cnt=0;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter the number :");
        a=Integer.parseInt(in.readLine());
       
        num=a;
        for(i=1;i<=a;i++)
        {
            if(num%i==0)
            {
                cnt++;
            }
           
           
        }
        if(cnt==2 && a!=2)
            {
                System.out.println(a+ " is Prime");
            }
            else
            {
                System.out.println(a+ " is not prime");
            }   
    }
}

/*--------------------------------------------------OUTPUT-------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac prime.java
Note: prime.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java prime
Enter the number :19
19 is Prime
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$


----------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
10] Constructors and Destructor using java
---------------------------------------------------------------------------------------------------------------------------------*/
import java.io.*;

class sample
{
    int a,b;
    sample()
    {
        System.out.println("Default constructor is called");
    }
   
    sample(int x,int y)
    {
        a=x;
        b=y;
        System.out.println("Parameterised constructor called");
        System.out.println(x+"    "+y);
    }
   
    sample(sample s)
    {
       
        System.out.println("Copy constructor called "+s.a+"   "+s.b);
    }
   
    public static void main(String args[])
    {
        sample s=new sample();
        sample s1=new sample(12,14);
        sample s2=new sample(s1);
        System.out.println("Hello world");
        s=null;        //release memory
        s1=null;
        s2=null;
        System.gc();    //garbage collection
    }
   
    protected void finalize ()
    {
        System.out.println("Destructor is called");
    }
}

/*---------------------------------------------------------OUTPUT------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac sample.java
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java sample
Default constructor is called
Parameterised constructor called
12    14
Copy constructor called 12   14
Hello world
Destructor is called
Destructor is called
Destructor is called
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

---------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------
11] Accept selling price and cost price of any item from user and find the profit/loss if any...

------------------------------------------------------------------------------------------------------------*/
import java.io.*;
class profit
{
    public static void main (String args[]) throws IOException
    {
        int cp,sp,var;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter cost price :");
        cp=Integer.parseInt(in.readLine());
       
        System.out.print("Enter selling price :");
        sp=Integer.parseInt(in.readLine());
       
        if(sp>cp)
        {
            var=sp-cp;
            System.out.println("There is a profit of " +var+ " /-");
           
        }
        else if(cp>sp)
        {
            var=cp-sp;
            System.out.println("There is a loss of " +var+ " /-");
        }
       
        else
        {
            System.out.println("Neither profit nor loss");
        }
       
       
    }
}

/*-------------------------------------------OUTPUT-------------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac profit.java
Note: profit.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java profit
Enter cost price :100
Enter selling price :88
There is a loss of 12 /-
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

--------------------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------
    12] To study single level inheritance.
-------------------------------------------------------------------------------------------*/
import java.io.*;//single level inheritance
class single    //parent class
{
        public int a;
    public void accept() throws IOException
    {

        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter a :");
        a=Integer.parseInt(in.readLine());
    }
}
class B extends single        //derived class
{
    int b;
    public void get() throws IOException
    {
   
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter b :");
    b=Integer.parseInt(in.readLine());
    }
   
    public void disp()
    {
        System.out.println("The entered values are :" +a+ " "+b);
    }
   
    public static void main(String args[]) throws IOException
    {
       
        B s1=new B();
        s1.accept();
        s1.get();
        s1.disp();
    }
   
}


/*----------------------------------------------------------------OUTPUT---------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac B.java
Note: B.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java B
Enter a :34
Enter b :67
The entered values are :34 67
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$

------------------------------------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------------------------------------------
13]  Single level inheritance using Java
 PROBLEM STATEMENT: Create class employee and accept details like employee name,post &code in it.
         By using single level inheritance inherit class employee info in derived class salary which accepts
         other details like salary and bonus.Print the entire information of an Employee.
----------------------------------------------------------------------------------------------------------------------*/
import java.io.*;//single level inheritance
class employee        //parent class employee
{
    String name,post;
    int code;
    public void accept() throws IOException
    {
   
    DataInputStream in=new DataInputStream(System.in);
   
    System.out.println("Enter the employee name");
    name=in.readLine();

    System.out.println("Enter the employee post");
    post=in.readLine();

    System.out.println("Enter the employee code");
    code=Integer.parseInt(in.readLine());

    }

}

class salary extends  employee //derived class salary from employee
{
    int sal,bonus;
    public void get() throws IOException
    {
   
    DataInputStream in=new DataInputStream(System.in);
    System.out.println("Enter the employee salary");
    sal=Integer.parseInt(in.readLine());

    System.out.println("Enter the employee bonus");
    bonus=Integer.parseInt(in.readLine());
   
    }

    public void disp() throws IOException
    {
    System.out.println(" Name :" +name);
    System.out.println(" Post :" +post);
    System.out.println(" Code :" +code);
    System.out.println(" Salary :" +sal);
    System.out.println(" Bonus :" +bonus);

    }
    public static void main(String args[]) throws IOException
    {
    salary s1=new salary();    //create object of derived class salary
    s1.get();        // get employee's name,post &code from parent class
    s1.accept();        //accept employee's salary and bonus from derived class
    s1.disp();        //display entire information
    }
}


/*------------------------------------------------------OUTPUT--------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac salary.java
Note: salary.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java salary
Enter the employee salary
10000
Enter the employee bonus
120
Enter the employee name
SonaliDhurjad
Enter the employee post
Administrator
Enter the employee code
1232
 Name :SonaliDhurjad
 Post :Administrator
 Code :1232
 Salary :10000
 Bonus :120
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$
------------------------------------------------------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------------------------------------------------
14] To study multilevel inheritance
STATEMENT : Print multiplication of three nos as an input from user using multilevel inheritance.
----------------------------------------------------------------------------------------------------------------------------*/

import java.io.*;    //multilevel inheritance

class multiA        //base class
{
    int a;
    public void  accept() throws IOException
    {
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter a :");
    a=Integer.parseInt(in.readLine());
    }
}
class multiB extends multiA    //derived class
{
    int b;
    public void  get() throws IOException
    {
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter b :");
    b=Integer.parseInt(in.readLine());
    }
}

class multiC extends multiB    //derived derived class
{
    int c,mult;
    public void  accept1() throws IOException
    {
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter c :");
    c=Integer.parseInt(in.readLine());
    }
   
    public void  calc() throws IOException
    {
        mult=a*b*c;
        System.out.println("Multiplication is " +mult);
    }
    public static void main(String args[])throws IOException
    {
    multiC m=new multiC();
    m.accept();   
    m.get();
    m.accept1();
    m.calc();

    }
}
/*---------------------------------------------------------OUTPUT--------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac multiC.java
Note: multiC.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java multiC
Enter a :2
Enter b :3
Enter c :4
Multiplication is 24
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$

--------------------------------------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------------------
15]  To study Heirarchical inheritance in Java
-------------------------------------------------------------------------------------------------------------*/
import java.io.*;    //heirarchical inheritance

class A        //parent class
{
    public int a;
    public void geta() throws IOException
    {
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter a:");
        a=Integer.parseInt(in.readLine());
    }
}
class B extends  A    //derived class of parent A
{
    int b;
    public void getb() throws IOException
    {
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter b:");
        b=Integer.parseInt(in.readLine());
    }
    public void disp1()
    {
        System.out.println("The entered values of a and b are " +a+ " " +b);
    }
   
}

class heirarchical extends A        //derived class of parent A
{
    int c;
    public void getc() throws IOException
    {
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter c:");
        c=Integer.parseInt(in.readLine());
    }

    public void disp2()
    {
        System.out.println("The entered values of a and c are " +a+ " " +c);
    }

    public static void main(String args[])throws IOException
    {
        B h1=new B();
        heirarchical h=new heirarchical();
       
        h1.geta();
        h1.getb();
        h1.disp1();
       
        h.getc();
        h.geta();
        h.disp2();

       
    }

   
}
/*--------------------------------------------------------OUTPUT------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac heirarchical.java
Note: heirarchical.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java heirarchical
Enter a:12
Enter b:9
The entered values of a and b are 12 9
Enter c:45
Enter a:12
The entered values of a and c are 12 45
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$

---------------------------------------------------------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------------
   16]  To study Hybrid Inheritance...
----------------------------------------------------------------------------------------------------*/

import java.io.*;    //hybrid inheritance
class A
{
    int a;
    public void  accepta() throws IOException
    {
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter a :");
    a=Integer.parseInt(in.readLine());
    }
}

class B extends A
{
    int b;
    public void  acceptb() throws IOException
    {
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter b :");
    b=Integer.parseInt(in.readLine());
    }
}

class C extends B
{
    int c;
    public void  acceptc() throws IOException
    {
    DataInputStream in=new DataInputStream(System.in);
    System.out.print("Enter c :");
    c=Integer.parseInt(in.readLine());
    }
}


class D extends C
{
    public void disp1()
    {
        System.out.println(a+ " " +b+ " "+c);
    }
}

class hybrid extends C
{
    public void disp2()
    {
        System.out.println(a+ " " +b+ " "+c);
    }

    public static void main(String args[]) throws IOException
    {
        D d=new D();
        d.accepta();
        d.acceptb();
        d.acceptc();
        d.disp1();
       
        hybrid h=new hybrid();
        h.accepta();
        h.acceptb();
        h.acceptc();
        h.disp2();
    }
}
/*-------------------------------------------OUTPUT-----------------------------------------
navin@navin-Lenovo-IdeaPad-Z510:~/Desktop/crashcourse/15-12-16$ javac hybrid.java
Note: hybrid.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
navin@navin-Lenovo-IdeaPad-Z510:~/Desktop/crashcourse/15-12-16$ java hybrid
Enter a :1
Enter b :2
Enter c :3
1 2 3
Enter a :2
Enter b :3
Enter c :4
2 3 4
navin@navin-Lenovo-IdeaPad-Z510:~/Desktop/crashcourse/15-12-16$


----------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------------
17] To study Heirarchical inheritance and overriding using Java
-----------------------------------------------------------------------------------------------------------*/
import java.io.*;
class Property
{
    public void eat()
    {
        System.out.println("can eat");
    }
    public void fly()
    {
        System.out.println("can fly");
    }
   
}

class cow extends Property
{
    public void eat()
    {
        System.out.println(" cow can eat");
    }
    public void fly()
    {
        System.out.println(" cow cant fly");
    }
}
class Penguin extends Property
{
    public void eat()
    {
        System.out.println(" Penguin can eat");
    }
    public void fly()
    {
        System.out.println(" Penguin can partially fly");
    }
}

class flycrow extends Property
{
    public void eat()
    {
        System.out.println(" crow can eat");
    }
    public void fly()
    {
        System.out.println(" crow can fly");
    }

    public static void main(String args[])
    {
        cow c=new cow();
        Penguin p=new Penguin();
        flycrow f=new flycrow();

        c.eat();
        c.fly();

        p.eat();
        p.fly();

        f.eat();
        f.fly();
    }
}

/*---------------------------------------------------------------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac flycrow.java
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java flycrow
 cow can eat
 cow cant fly
 Penguin can eat
 Penguin can partially fly
 crow can eat
 crow can fly
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$

-------------------------------------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------------------------
 18] To study Abstract class using Java
-------------------------------------------------------------------------------------------------------*/
import java.io.*;

abstract class Abstrct
{
    abstract void get() throws IOException;
    abstract void disp() throws IOException;
}

class Abs extends Abstrct
{
    int a;
    void get() throws IOException
    {
       
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter a :");
        a=Integer.parseInt(in.readLine());
    }
     void disp()
    {
       
        System.out.println("The value of a :" +a+ "\n");
       
    }
    public static void main(String args[]) throws IOException
    {
        Abs a1=new Abs();
        a1.get();   
        a1.disp();
    }
}
/*--------------------------------------------------OUTPUT---------------------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac Abs.java
Note: Abs.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java Abs
Enter a :12
The value of a :12

ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$

-------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------
19] To study interface in Java
---------------------------------------------------------------------------------------------------------*/
import java.io.*;

interface A
{
    int a=10;
    void disp1();
}

interface B
{
    int b=10;
    void disp2();
}

class base
{
    int num;
    DataInputStream in=new DataInputStream(System.in);
    public void accept()throws IOException
    {
        System.out.print("Enter the number :");
        num=Integer.parseInt(in.readLine());
    }
   
    public void show()
    {
        System.out.println("The number is :"+num);
    }

}

class derived extends base implements  A,B
{
    public void disp1()
    {
        System.out.println(" The value of a is :"+a);
    }

    public void disp2()
    {
        System.out.println(" The value of b is :"+b);
    }
   
    public static void main(String args[]) throws IOException
    {
        derived b=new derived();
        b.accept();
        b.show();
        b.disp1();
        b.disp2();
    }
}

/*----------------------------------------------------------OUTPUT-----------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ javac derived.java
Note: derived.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$ java derived
Enter the number :12
The number is :12
 The value of a is :10
 The value of b is :10
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/15-12-16$

-----------------------------------------------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------------------------------------
20] Swap without using third variable using java
----------------------------------------------------------------------------------------------------------*/

import java.io.*;
class swap
{
    public static void main(String args[]) throws IOException
    {
        int a,b;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter a :");
        a=Integer.parseInt(in.readLine());
       
        System.out.print("Enter b :");
        b=Integer.parseInt(in.readLine());

        a=a+b;
       
        b=a-b;
        System.out.print("Swap of b is : " +b+ "\n");
       
        a=a-b;
        System.out.print("Swap of a is : " +a+ "\n");
       
       
    }
}

/*---------------------------------------------------------OUTPUT-----------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac swap.java
Note: swap.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java swap
Enter a :34
Enter b :21
Swap of b is : 34
Swap of a is : 21
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

---------------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------
 21] Java program to find salary of Employee
----------------------------------------------------------------------------------------------*/
import java.io.*;
class salary
{
    public static void main(String args[]) throws IOException
    {
        String gen;
        int yr,qual;
   
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.println("Enter the Gender (M/F) : ");
        gen=in.readLine();
       
        System.out.println("Enter the Experience Year : ");
        yr=Integer.parseInt(in.readLine());
       
        System.out.println("1.Post Graduate");
        System.out.println("2.Graduate");
        System.out.print("Enter the qualification (1/2) :");
        qual=Integer.parseInt(in.readLine());
       
       
        if((gen.equals("M")) && (yr>=10) && (qual==1))
        {
            System.out.println("Salary is 15000/-");
        }
       
        else if((gen.equals("M")) && (yr>=10) && (qual==2))
        {
            System.out.println("Salary is 10000/-");
        }
       
        else if((gen.equals("M")) && (yr<10) && (qual==1))
        {
            System.out.println("Salary is 10000/-");
        }
        else if((gen.equals("M")) && (yr<10) && (qual==2))
        {
            System.out.println("Salary is 7000/-");
        }
       
        else if((gen.equals("F")) && (yr>=10) && (qual==1))
        {
            System.out.println("Salary is 12000/-");
        }
       
        else if((gen.equals("F")) && (yr>=10) && (qual==2))
        {
            System.out.println("Salary is 9000/-");
        }
       
        else if((gen.equals("F")) && (yr<10) && (qual==1))
        {
            System.out.println("Salary is 10000/-");
        }
        else if((gen.equals("F")) && (yr<10) && (qual==2))
        {
            System.out.println("Salary is 6000/-");
        }
        else
        {
            System.out.println("Sorry !!! Try Again....");
        }
    }
}

/*------------------------------------------------OUTPUT------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac salary.java
Note: salary.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java salary
Enter the Gender (M/F) :
F
Enter the Experience Year :
12
1.Post Graduate
2.Graduate
Enter the qualification (1/2) :1
Salary is 12000/-
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

------------------------------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------------------------------
22] Java program to find result of student from entered marks
------------------------------------------------------------------------------------------------------*/

import java.io.*;

class result
{
    public static void main(String args[]) throws IOException
    {
        int marks;
        DataInputStream in=new DataInputStream(System.in);
       
        System.out.print("Enter the marks of students :");
        marks=Integer.parseInt(in.readLine());
       
        if(marks>=75)
        {
            System.out.println("Result is Distinction");
        }
       
        else if(marks>=60 && marks<75)
        {
            System.out.println("Result is First Class");
        }
       
        else if(marks>=51 && marks<60)
        {
            System.out.println("Result is Higher Second Class ");
        }
       
        else if(marks>=45 && marks<51)
        {
            System.out.println("Result is Second Class");
        }
       
        else if(marks>=40 && marks<45)
        {
            System.out.println("Result is Pass Class");
        }
       
        else
        {
            System.out.println("Result is Fail");
        }
    }
   
}

/*--------------------------------------------------------OUTPUT---------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac result.java
Note: result.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java result
Enter the marks of students :60
Result is First Class
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------
23] Find area of triangle
--------------------------------------------------------------------------------------------------------*/
import java.io.*;

class area
{
    public static void main(String args[]) throws IOException
    {
        float b,h,area;
       
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter the base :");
        b=Integer.parseInt(in.readLine());
       
        System.out.print("Enter the height :");
        h=Integer.parseInt(in.readLine());
       
        area=(b*h)/2;
       
        System.out.println("Area of Triangle is "+area+ " sqm");
    }
}

/*------------------------------------------------------OUTPUT--------------------------------------------------
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ javac area.java
Note: area.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$ java area
Enter the base :60
Enter the height :40
Area of Triangle is 1200.0 sqm
ubantu@ubantu-HP-630-Notebook-PC:~/Desktop/crashcourse/14-12-16$

-----------------------------------------------------------------------------------------------------------------*/

/************************************************************************
24] PATTERN :

 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6


**************************************************************************/

import java.io.*;

class pattern2
{
    public static void main(String args[])throws IOException
    {
        int i,j,n;
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter n :");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                System.out.print(" "+j+" ");
            }
            System.out.print("\n");
           
        }
    }
   
}
/**********************************OUTPUT**********************************
ubuntu@ubuntu-HP-630-Notebook-PC:~$ cd Desktop/31-12-2016/
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern2.java
Note: pattern2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern2
Enter n :6
 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6
 1  2  3  4  5  6
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$
-------------------------------------------------------------------------------------------------------------------------*/


/**************************************************************************
25] PATTERN :

 1  1  1  1  1  1  1  1  1
 2  2  2  2  2  2  2  2  2
 3  3  3  3  3  3  3  3  3
 4  4  4  4  4  4  4  4  4
 5  5  5  5  5  5  5  5  5
 6  6  6  6  6  6  6  6  6
 7  7  7  7  7  7  7  7  7
 8  8  8  8  8  8  8  8  8
 9  9  9  9  9  9  9  9  9

***************************************************************************/

import java.io.*;

class pattern3
{
    public static void main(String args[])throws IOException
    {
        int i,j,n;
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter n :");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                System.out.print(" "+i+" ");
            }
            System.out.print("\n");
          
        }
    }
   
}

/*******************************OUTPUT*******************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern3.java
Note: pattern3.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern3
Enter n :9
 1  1  1  1  1  1  1  1  1
 2  2  2  2  2  2  2  2  2
 3  3  3  3  3  3  3  3  3
 4  4  4  4  4  4  4  4  4
 5  5  5  5  5  5  5  5  5
 6  6  6  6  6  6  6  6  6
 7  7  7  7  7  7  7  7  7
 8  8  8  8  8  8  8  8  8
 9  9  9  9  9  9  9  9  9

ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


*******************************************************************************/

/*********************************************************************
26] PATTERN :
 1  2  3
 4  5  6
 7  8  9
**********************************************************************/

import java.io.*;

class pattern4
{
    public static void main(String args[])throws IOException
    {
        int i,j,n,num=1;
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter n :");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                System.out.print(" "+num+" ");
                num++;
            }
            System.out.print("\n");
          
        }
    }
   
}

/*****************************************OUTPUT************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern4.java
Note: pattern4.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern4
Enter n :3
 1  2  3
 4  5  6
 7  8  9
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


********************************************************************************/

/****************************************************************************
27] PATTERN 5 :
 1  0  0  0  0  0  0  0  0  0
 0  1  0  0  0  0  0  0  0  0
 0  0  1  0  0  0  0  0  0  0
 0  0  0  1  0  0  0  0  0  0
 0  0  0  0  1  0  0  0  0  0
 0  0  0  0  0  1  0  0  0  0
 0  0  0  0  0  0  1  0  0  0
 0  0  0  0  0  0  0  1  0  0
 0  0  0  0  0  0  0  0  1  0
 0  0  0  0  0  0  0  0  0  1
******************************************************************************/

import java.io.*;

class pattern5
{
    public static void main(String args[])throws IOException
    {
        int i,j,n;
        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter n :");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(i==j)
                {
                    System.out.print(" 1 ");
                }
                else
                {
                    System.out.print(" 0 ");
                }
            }
            System.out.print("\n");
           
        }
    }
   
}

/**************************************OUTPUT**********************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern5.java
Note: pattern5.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern5
Enter n :10
 1  0  0  0  0  0  0  0  0  0
 0  1  0  0  0  0  0  0  0  0
 0  0  1  0  0  0  0  0  0  0
 0  0  0  1  0  0  0  0  0  0
 0  0  0  0  1  0  0  0  0  0
 0  0  0  0  0  1  0  0  0  0
 0  0  0  0  0  0  1  0  0  0
 0  0  0  0  0  0  0  1  0  0
 0  0  0  0  0  0  0  0  1  0
 0  0  0  0  0  0  0  0  0  1
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


*******************************************************************************/

/****************************************************************************************
28] PROBLEM :Java Program to print alphabets a-z...

*****************************************************************************************/

import java.io.*;

class pattern6 //alphabets
{
    public static void main(String args[])
    {
        char ch;
        for( ch = 'a' ; ch <= 'z' ; ch++ )
        {
            System.out.print(" "+ch+" ");
        }
    System.out.print("\n");
    }
}
/***********************************OUTPUT*************************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern6.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern6
 a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


******************************************************************************************/
/****************************************************************************************
29] PROBLEM :Java Program to print alphabets A-Z...

*****************************************************************************************/

import java.io.*;

class pattern7 //alphabets
{
    public static void main(String args[])
    {
        char ch;
        for( ch = 'A' ; ch <= 'Z' ; ch++ )
        {
            System.out.print(" "+ch+" ");
        }
    System.out.print("\n");
    }
}
/***********************************OUTPUT*************************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern7.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern7
 A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$

******************************************************************************************/


/***********************************************************************************
30] PATTERN :

 A  B  C  D
 A  B  C  D
 A  B  C  D
 A  B  C  D
***********************************************************************************/
import java.io.*;
class pattern8
{
    public static void main(String args[])
    {
        char i,j;
        for(i='A';i<='D';i++)
        {
            for(j='A';j<='D';j++)
            {
                System.out.print(" "+j+" ");
            }
            System.out.print("\n");
        }
    }
}

/***********************************OUTPUT*******************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern8.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern8
 A  B  C  D
 A  B  C  D
 A  B  C  D
 A  B  C  D
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


**************************************************************************************/

/***********************************************************************************
31] PATTERN :

 A  A  A  A
 B  B  B  B
 C  C  C  C
 D  D  D  D
***********************************************************************************/
import java.io.*;
class pattern9
{
    public static void main(String args[])
    {
        char i,j;
        for(i='A';i<='D';i++)
        {
            for(j='A';j<='D';j++)
            {
                System.out.print(" "+i+" ");
            }
            System.out.print("\n");
        }
    }
}

/***********************************OUTPUT*******************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern9.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern9
 A  A  A  A
 B  B  B  B
 C  C  C  C
 D  D  D  D
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$



**************************************************************************************/

/***********************************************************************************
32] PATTERN :

 A  B  C  D  E
 F  G  H  I   J
 K  L  M  N  O
 P  Q  R  S  T
 U  V  W  X  Y
***********************************************************************************/
import java.io.*;
class pattern10
{
    public static void main(String args[])
    {
        char i,j,num='A';
        for(i='A';i<='E';i++)
        {
            for(j='A';j<='E';j++)
            {
                System.out.print(" "+num+" ");
                num++;
            }
            System.out.print("\n");
        }
    }
}

/***********************************OUTPUT*******************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern10.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern10
 A  B  C  D  E
 F  G  H  I  J
 K  L  M  N  O
 P  Q  R  S  T
 U  V  W  X  Y
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


**************************************************************************************/

/***********************************************************************************
33] PATTERN :
 A  B  C  D  E  F  G  H  I  J  K  L
 M  N  O  P  Q  R  S  T  U  V  W  X
 Y  Z  [  \  ]  ^  _  `  a  b  c  d
 e  f  g  h  i  j  k  l  m  n  o  p
 q  r  s  t  u  v  w  x  y  z  {  |


***********************************************************************************/
import java.io.*;
class pattern11
{
    public static void main(String args[])
    {
        char i,j,num='A';
        for(i='A';i<='E';i++)
        {
            for(j='A';j<='L';j++)
            {
                System.out.print(" "+num+" ");
                num++;
            }
            System.out.print("\n");
        }
    }
}

/***********************************OUTPUT*******************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern11.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern11
 A  B  C  D  E  F  G  H  I  J  K  L
 M  N  O  P  Q  R  S  T  U  V  W  X
 Y  Z  [  \  ]  ^  _  `  a  b  c  d
 e  f  g  h  i  j  k  l  m  n  o  p
 q  r  s  t  u  v  w  x  y  z  {  |
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$



**************************************************************************************/

/************************************************************************************
33] PATTERN :

 *
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  *
 *  *  *  *  *  *
 *  *  *  *  *  *  *

*************************************************************************************/
import java.io.*;
class pattern12
{
    public static void main(String args[]) throws IOException
    {
        int i,j,n;

        DataInputStream in= new DataInputStream(System.in);
        System.out.print("Enter the size :");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=i;j++)
            {
                System.out.print(" * ");
            }
            System.out.print("\n");
        }
    }
}

/***************************************OUTPUT***************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern12.java
Note: pattern12.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern12
Enter the size :7
 *
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  *
 *  *  *  *  *  *
 *  *  *  *  *  *  *
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


**************************************************************************************/

/**************************************************************************************
34] PATTERN :

 *  *  *  *  *  *
 *  *  *  *  *
 *  *  *  *
 *  *  *
 *  *
 *

*****************************************************************************************/
import java.io.*;
class pattern13
{
    public static void main(String args[]) throws IOException
    {
        int i,j,n;

        DataInputStream in= new DataInputStream(System.in);
        System.out.print("Enter the size :");
        n=Integer.parseInt(in.readLine());
        for(i=1;i<=n;i++)
        {
            for(j=n;j>=i;j--)
            {
                System.out.print(" * ");
            }
            System.out.print("\n");
        }
    }
}

/***************************************OUTPUT********************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern13.java
Note: pattern13.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern13
Enter the size :6
 *  *  *  *  *  *
 *  *  *  *  *
 *  *  *  *
 *  *  *
 *  *
 *
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


********************************************************************************************/

/****************************************************************************************
35] PATTERN :

 1
 2  3
 4  5  6
 7  8  9  10
 11  12  13  14  15
 16  17  18  19  20  21

*******************************************************************************************/
import java.io.*;
class pattern14
{
    public static void main(String args[]) throws IOException
    {
        int i,j,n,num=1;

        DataInputStream in= new DataInputStream(System.in);
        System.out.print("Enter the size :");
        n=Integer.parseInt(in.readLine());
        for(i=0;i<n;i++)
        {
            for(j=0;j<=i;j++)
            {
                System.out.print(" "+num+" ");
                num++;
            }
            System.out.print("\n");
        }
    }
}

/*****************************************OUTPUT****************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern14.java
Note: pattern14.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern14
Enter the size :6
 1
 2  3
 4  5  6
 7  8  9  10
 11  12  13  14  15
 16  17  18  19  20  21
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$


*****************************************************************************************/
 /****************************************************************************************
36] PATTERN :
 A
 B  C
 D  E  F
 G  H  I  J
 

*******************************************************************************************/
import java.io.*;
class pattern15
{
    public static void main(String args[])
    {
        char i,j,num='A';

        for(i='A';i<='D';i++)
        {
            for(j='A';j<=i;j++)
            {
                System.out.print(" "+num+" ");
                num++;
            }
            System.out.print("\n");
        }
        System.out.print("\n");
    }
}

/*****************************************OUTPUT****************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ javac pattern15.java
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$ java pattern15
 A
 B  C
 D  E  F
 G  H  I  J

ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/31-12-2016$



*****************************************************************************************/

/**************************************************************************
37] PATTERN :

 *  *  *  *  *  *  *  *
    *  *  *  *  *  *  *
       *  *  *  *  *  *
          *  *  *  *  *
             *  *  *  *
                *  *  *
                   *  *
                      *

***************************************************************************/

import java.io.*;
class pattern16
{
    public static void main (String args[])throws IOException
    {
        int i,j,k,num;

        DataInputStream in=new DataInputStream(System.in);
        System.out.print("Enter the size :");
        num=Integer.parseInt(in.readLine());
        for(i=0;i<num;i++)
        {
            if(i>0)
            {
                for(k=0;k<i;k++)
                {       
                    System.out.print("   ");
                }
            }
            for(j=num;j>i;j--)
            {
                System.out.print(" * ");
            }
        System.out.print("\n");
        }
    }
}

/**************************************OUTPUT*****************************************
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/crashcourse/3-1-2017$ javac pattern16.java
Note: pattern16.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/crashcourse/3-1-2017$ java pattern16
Enter the size :8
 *  *  *  *  *  *  *  *
    *  *  *  *  *  *  *
       *  *  *  *  *  *
          *  *  *  *  *
             *  *  *  *
                *  *  *
                   *  *
                      *
ubuntu@ubuntu-HP-630-Notebook-PC:~/Desktop/crashcourse/3-1-2017$

***********************************************************************************/

38] Currency Convertor

import java.io.*;
public class currency_convertor
{

    public static void main(String[] args) throws IOException
    {
        // TODO Auto-generated method stub
        double rupees,conv;
        int ch;
        DataInputStream in= new DataInputStream(System.in);
      
        System.out.print("Enter the currency in Rupees :");
        rupees=Double.parseDouble(in.readLine());
      
        System.out.println("Which conversion you would prefer ?");
        System.out.print("\n**************MENU*************\n");
        System.out.print("\n1.Rupee To Dollar($) \n2.Rupee To Euros\n");
        System.out.println("Enter your Choice :");
        ch=Integer.parseInt(in.readLine());
      
        switch (ch)
        {
        case 1:
            conv=rupees*0.015;
            System.out.println(rupees+ " Rs/- is " +conv+ " $");
            break;

        case 2:
            conv=rupees*0.014;
            System.out.println(rupees+ " Rs/- is " +conv+ " Euros");
            break;

        default:
            System.out.println("Exit");
            break;
        }
    }

}


OUTPUT:
 Enter the currency in Rupees :45
Which conversion you would prefer ?

**************MENU*************

1.Rupee To Dollar($)
2.Rupee To Euros
Enter your Choice :
2
45.0 Rs/- is 0.63 Euros
********************************************************************************/