JAVA PROGRAMS INDEX PAGE

  •  BASIC PROGRAMS :

           1. To Print Hello World


    • ADDITION PROGRAMS USING VARIOUS METHOD :

          1. To add two number where numbers are already given or initialized
          2. To add two numbers where numbers will be given by user. Using Scanner method
          3. To add two numbers given by user using DataInputStream method
          4. To add two numbers where numbers will be given by user. Using java swing


    • SWAPPING PROGRAMS USING VARIOUS INPUT METHODS :

    1.  To find area of rectangle .  
    2.  Basic Calculator .   

    • IF - ELSE PROGRAMS :

    1.  To find the largest of three numbers
    2. Program to check whether a year entered is a leap year or not.
    3. To Check a number is Armstrong or not up to 3 digit
    4. Digit Checker program which checks the digit of the number up to 5 digit.
    5. To convert numbers between 100 and 999 into words form.

    • FOR LOOP PATTERNS :
    1. To print a Floyd's triangle
    2. To print a star pattern in odd numbers in form of right triangle
    3. To print a star pattern in form of right angle triangle
    4. To print a pattern or star triangle pattern

    • CONVERSION PROGRAM :
    1. To convert decimal to binary from 1 to 1024 numbers using if-else
    2. To convert binary to decimal from 1 to 2048 using if - else only.

    • OTHER PROGRAMS :
    1. To solve linear equation
    2. Program which gives area,volume and surface areas of various geometric figures
    3. TIC TAC TOE Game in java
    4. Payroll Management System in java
    5. Simple Quiz in Java
    6. Printing numbers 1 - 10 using Random in java
    7. Calendar or Day predictor
    8. Opening a File from your computer using Java

    Opening a File from your computer using Java

    • PROGRAM :
    import java.awt.Desktop;
    import java.io.File;
    import java.io.IOException;

    public class Filr {

        public static void main(String[] args) throws IOException {
            //text file, should be opening in default text editor
            File file = new File("// enter the file path here");
            
            //first check if Desktop is supported by Platform or not
            if(!Desktop.isDesktopSupported()){
                System.out.println("Desktop is not supported");
                return;
            }
            
            Desktop desktop = Desktop.getDesktop();
            if(file.exists()) desktop.open(file);
            
            //let's try to open PDF file
            file = new File("// enter your file path here");
            if(file.exists()) desktop.open(file);
        }


    }

    Calendar or Day predictor

    • This calendar start from 1 January 2000 .

    • PROGRAM :
    import java.util.Scanner;
    public class Calendar {
     
        public static void main(String[] args) {
         
            int x,y,z,d=0,a,i,count=0,d1=0,d2=0,d3=0,d4=0,d5=0,d6=0;
           
            int d7=0,d8=0,d9=0,d10=0,d11=0,d12=0,d13=0;        System.out.println("Enter the date in the form of DD");
            Scanner s=new Scanner (System.in);
            x= s.nextInt();
            System.out.println("Enter the month in the form of MM");
            y=s.nextInt();
            System.out.println("Enter the year in the form of YYYY");
            z=s.nextInt();
            a=z%100;
           
            for(i=2000;i<=z;i++)
            {
            if(i/4==0)
            {
            count=count+1;
            }
           
            }
           
         
            if(y==1){
             d=(a)*365 + count + x; d1=31;
             }
                if (y==2)
            {
             d=(a)*365 + count + d1+x;d2=31+28;
            }
            if(y==3){
              d=(a)*365 + count + d2+x; d3=31*2+28;
            }
            if(y==4 ){
            d=(a)*365 + count + d3+x; d4=31*2+28+30;
            }
                if (y==5)
            {
            d=(a)*365 + count + d4+x;d5=31*3+28+30;
            }
            if(y==6) {
            d=(a)*365 + count + d5+x;d6=31*3+28+30*2;
            }
            if(y==7 ){
            d=(a)*365 + count + d6+x; d7=31*4+28+30*2;
            }
                if (y==8)
            {
            d=(a)*365 + count + d7+x; d8=31*5+28+30*2;
            }
            if(y==9) {
            d=(a)*365 + count + d8+x; d9=31*5+28+30*3;
            }
            if(y==10){
            d=(a)*365 + count + d9+x; d10=31*6+28+30*3;
            }
                if (y==11)
            {
            d=(a)*365 + count + d10+x; d11=31*6+28+30*4;
            }
            if(y==12) {
            d=(a)*365 + count + d11+x;
            }
           
           
         
             if(z/4==0)
             {
              d=d+1;
             }
             d13=(d+1)%7;
             System.out.println("the day was:");
             if(d13==1){System.out.println("Saturday");}
              if(d13==2){System.out.println("Sunday");}
               if(d13==3){System.out.println("Monday");}
                if(d13==4){System.out.println("Tuesday");}
                 if(d13==5){System.out.println("Wednesday");}
                  if(d13==6){System.out.println("Thursday");}
                   if(d13==0){System.out.println("Friday");}
       
        }
    }

    • OUTPUT :
    Enter the date in the form of DD
    23
    Enter the month in the form of MM
    03
    Enter the year in the form of YYYY
    2017
    the day was:

    thursday

    Printing numbers 1 - 10 using Random in java

    • PROGRAM :
    import java.util.*;
    public class Qr {
          
        public static void main(String[] args) {
           
              Random rn = new Random();
               int a[] = new int[20];
            
            int i=0,j=0;
           
            for(i=0;i<10;i++)
            { 
            a[i]=rn.nextInt(10);
            for(j=0;j<i;j++){
           
            if(a[i]== a[j])
            {
            i--;
            }}
            
            }
          
           for(i=0;i<10;i++)
           {System.out.println("array is : "+a[i]);
           }

        }
    }


    • output :
    array is : 2

    array is : 7
    array is : 3
    array is : 8
    array is : 5
    array is : 9
    array is : 4
    array is : 0
    array is : 6

    array is : 1

    Simple Quiz in java.

    • PROGRAM :

    import java.io.*;

    public class Quiz {

       public static void main(String[] args) throws IOException {

        

           int  count=0;

           String z;

            System.out.println("----------- PLAY QUIZ -----------");

            String x = "Ques : Object Oriented programming means ? ";

            System.out.println(x);

            String a =" A. being objective about what you develop.";

            String b =" B. Designing the application based on the object discovered while analysing the problem";

            String c =" C. Writing an algorithm before the Program";

            String d =" D. Writing a java program with class.";

           System.out.println(a);

           System.out.println(b);

           System.out.println(c);

           System.out.println(d);

           System.out.println("Enter your answer as option a,b,c,d");

           DataInputStream s = new DataInputStream(System.in);

           z=s.readLine();

           if(z.equalsIgnoreCase("a"))

           {

            count = count+1;

           }

            String y = "Ques : An object could be ? ";

            System.out.println(y);

            String a1 =" A.  Anything.";

            String b1 =" B. Data container";

            String c1 =" C.  Program";

            String d1 =" D. Algorithm.";

           System.out.println(a1);

           System.out.println(b1);

           System.out.println(c1);

           System.out.println(d1);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("a"))

           {

            count = count+1;

           }

            

             String w = "Ques : Which is a valid keyword in java amoung the following ? ";

            System.out.println(w);

            String a2 =" A.  unsigned.";

            String b2 =" B. String";

            String c2 =" C.  Float";

            String d2 =" D. interface.";

           System.out.println(a2);

           System.out.println(b2);

           System.out.println(c2);

           System.out.println(d2);

             System.out.println("Enter your answer");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("d"))

           {

            count = count+1;

           }

            

             String v = "Ques : String in a java is ? ";

            System.out.println(v);

            String a3 =" A.  object.";

            String b3 =" B. class";

            String c3 =" C.  variable";

            String d3 =" D. character array.";

           System.out.println(a3);

           System.out.println(b3);

           System.out.println(c3);

           System.out.println(d3);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("b"))

           {

            count = count+1;

           }

           

            String u = "Ques : Which of the following has always first word small and all other capital  ? ";

            System.out.println(u);

            String a4 =" A.  class.";

            String b4 =" B. object";

            String c4 =" C.  method";

            String d4 =" D. keywords.";

           System.out.println(a4);

           System.out.println(b4);

           System.out.println(c4);

           System.out.println(d4);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("c"))

           {

            count = count+1;

           }

           

            String t = "Ques : Which of the folllowing method of string class is used to obtain a character at specific index ? ";

            System.out.println(t);

            String a5 =" A.  char().";

            String b5 =" B. Charat()";

            String c5 =" C.  charat()";

            String d5 =" D. charAt().";

           System.out.println(a5);

           System.out.println(b5);

           System.out.println(c5);

           System.out.println(d5);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("d"))

           {

            count = count+1;

           }

           

            String p = "Ques : Which of these class in not a member of java.io.* package ? ";

            System.out.println(p);

            String a6 =" A.  String.";

            String b6 =" B.  String reader";

            String c6 =" C.  writer";

            String d6 =" D. file.";

           System.out.println(a6);

           System.out.println(b6);

           System.out.println(c6);

           System.out.println(d6);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("a"))

           {

            count = count+1;

           }

            String r = "Ques : Which of these are selection statements ? ";

            System.out.println(r);

            String a7 =" A.  for().";

            String b7 =" B. if()";

            String c7 =" C.  break";

            String d7 =" D. switch().";

           System.out.println(a7);

           System.out.println(b7);

           System.out.println(c7);

           System.out.println(d7);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("b"))

           {

            count = count+1;

           }

           

            String g = "Ques : Which of the following function is not available in java  ? ";

            System.out.println(g);

            String a8 =" A.  String.";

            String b8 =" B. functions";

            String c8 =" C.  pointers";

            String d8 =" D. array.";

           System.out.println(a8);

           System.out.println(b8);

           System.out.println(c8);

           System.out.println(d8);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("c"))

           {

            count = count+1;

           }

           

            String h = "Ques : Java language was released in ? ";

            System.out.println(h);

            String a9 =" A.  1999.";

            String b9 =" B. 1996";

            String c9 =" C.  1994";

            String d9 =" D. 1995.";

           System.out.println(a9);

           System.out.println(b9);

           System.out.println(c9);

           System.out.println(d9);

             System.out.println("Enter your answer as option a,b,c,d");

           

           z=s.readLine();

           if(z.equalsIgnoreCase("d"))

           {

            count = count+1;

           }

           System.out.println(" Total correct answer are : " +count);

           System.out.println(" CONCLUSION :");

           if(count == 8 || count== 9 || count == 10)

           { System.out.println("You have very good knowledge of java");

           }

           else if(count==6 || count == 7 || count == 5)

           { System.out.println("you are advised to give more time to java . try next time" );

           }

           else { System.out.println("You need to start with basic fundamentals again.. ");

           }

        }

    }

    • OUTPUT :
    ----------- PLAY QUIZ -----------
    Ques : Object Oriented programming means ? 
     A. being objective about what you develop.
     B. Designing the application based on the object discovered while analysing the problem
     C. Writing an algorithm before the Program
     D. Writing a java program with class.
    Enter your answer as option a,b,c,d
    a
    Ques : An object could be ? 
     A.  Anything.
     B. Data container
     C.  Program
     D. Algorithm.

    Enter your answer as option a,b,c,d

    Java Program Index Page

    •  BASIC PROGRAMS :

             1. To Print Hello World

      • ADDITION PROGRAMS USING VARIOUS METHOD :

            1. To add two number where numbers are already given or initialized
            2. To add two numbers where numbers will be given by user. Using Scanner method
            3. To add two numbers given by user using DataInputStream method
            4. To add two numbers where numbers will be given by user. Using java swing

      • SWAPPING PROGRAMS USING VARIOUS INPUT METHODS :

      1.  To find area of rectangle .  
      2.  Basic Calculator .   

      • IF - ELSE PROGRAMS :

      1.  To find the largest of three numbers
      2. Program to check whether a year entered is a leap year or not.
      3. To Check a number is Armstrong or not up to 3 digit
      4. Digit Checker program which checks the digit of the number up to 5 digit.
      5. To convert numbers between 100 and 999 into words form.

      • FOR LOOP PATTERNS :
      1. To print a Floyd's triangle
      2. To print a star pattern in odd numbers in form of right triangle
      3. To print a star pattern in form of right angle triangle
      4. To print a pattern or star triangle pattern

      • CONVERSION PROGRAM :
      1. To convert decimal to binary from 1 to 1024 numbers using if-else
      2. To convert binary to decimal from 1 to 2048 using if - else only.
      • MORE PROGRAMS :
      1. To solve linear equation
      2. Program which gives area,volume and surface areas of various geometric figures
      • PROJECTS AND GAMES :
      1. TIC TAC TOE Game in java
      2. Payroll Management System in java

      TIC TAC TOE Game in java

      PROGRAM :

      import java.util.*;
      public class TicT {
              
         
          public static void main(String[] args) {
            
              System.out.println("----------------/ TIC TAC TOE /-------------");
               int a[][] = new int [3][3];
               int i,j,c,r;
               for(i=0;i<3;i++)
               {
                for(j=0;j<3;j++){
                 System.out.print("_  |");
                }
                System.out.println();
               }
               System.out.println("ENTER THE ROW:");
               Scanner s = new Scanner (System.in);
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
               a[r-1][c-1]=1;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0)
                System.out.print("_ ");
                else
                System.out.print("X ");
              }
              System.out.println("");
            }
              System.out.println("PLAYER '0' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=2;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2)
                System.out.print("0 ");
                else if(a[i][j]==1)
                System.out.print("X ");
              }
              System.out.println("");
            }
             System.out.println("PLAYER 'X' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=3;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            }
               System.out.println("PLAYER '0' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=4;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2 || a[i][j]==4)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            }
              System.out.println("PLAYER 'X' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=5;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2||a[i][j]==4)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            } 
               
              if(a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==1 ||a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==3|| a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==5)
              {
              System.out.println("PLAYER'X' WINS");
              }
               if( a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==1 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==3 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==5 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if( a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==1 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==3 ||  a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==5 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if(  a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==1 || a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==3 ||  a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==5 )
              {
              System.out.println("PLAYER'X' WINS");
              }
              if(  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==1 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==3 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==5 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if(  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==1 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==3 || a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==5)
              {
              System.out.println("PLAYER'X' WINS");
              }
              
              System.out.println("PLAYER '0' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=6;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2||a[i][j]==4 ||a[i][j]==6)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            } 
               
              if(a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==1 ||a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==3|| a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==5)
              {
              System.out.println("PLAYER'0' WINS");
              }
               if( a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==2 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==4 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==6 )
              {
              System.out.println("PLAYER'0' WINS");
              }
               if( a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==2 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==4 ||  a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==6 )
              {
              System.out.println("PLAYER'0' WINS");
              }
               if(  a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==2 || a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==4 ||  a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==6 )
              {
              System.out.println("PLAYER'0' WINS");
              }
              if(  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==2 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==4 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==6 )
              {
              System.out.println("PLAYER'0' WINS");
              }
               if(  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==2 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==4 || a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==6)
              {
              System.out.println("PLAYER'0' WINS");
              }
              
              System.out.println("PLAYER 'X' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=7;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2||a[i][j]==4 || a[i][j]==6)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            } 
               
              if(a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==1 ||a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==3|| a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==5)
              {
              System.out.println("PLAYER'X' WINS");
              }
               if( a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==1 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==3 ||
                a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==5 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==7 )       {
              System.out.println("PLAYER'X' WINS");
              }
               if( a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==1 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==3 ||  
                a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==5 ||a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==7 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if(  a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==3  || a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==3 ||  
                a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==5 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==7)
              {
              System.out.println("PLAYER'X' WINS");
              }
              if(  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==1 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==3 || 
              a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==5 || a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==7 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if(  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==1 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==3 || 
                a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==5 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==7)
              {
              System.out.println("PLAYER'X' WINS");
              }
              
              
              System.out.println("PLAYER '0' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=8;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2||a[i][j]==4 || a[i][j]==6 || a[i][j]==8)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            } 
               
              if(a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==2 ||a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==4||
              a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==6 || a[1][1]==a[2][2] && a[2][2]==a[3][3] &&a[3][3]==8)
              {
              System.out.println("PLAYER'0' WINS");
              }
               if( a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==2 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==4 ||
                a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==6 || a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==8)
              {
              System.out.println("PLAYER'0' WINS");
              }
               if( a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==2 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==4 || 
                a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==6 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==8 )
              {
              System.out.println("PLAYER'0' WINS");
              }
               if(  a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==2 || a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==4 ||  
                a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==6 ||a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==8 )
              {
              System.out.println("PLAYER'0' WINS");
              }
              if(  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==2 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==4 || 
              a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==6 || a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==8)
              {
              System.out.println("PLAYER'0' WINS");
              }
               if(  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==2 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==4 ||
                a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==6 || a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==4)
              {
              System.out.println("PLAYER'0' WINS");
              }
              
              System.out.println("PLAYER 'X' CHANCE");
               System.out.println("ENTER THE ROW:");
             
               c=s.nextInt();
               System.out.println("Enter coloumn");
               r=s.nextInt();
                a[r-1][c-1]=9;
                for(i=0;i<3;i++)
            { for(j=0;j<3;j++)
              { if(a[i][j]==0 )
                System.out.print("_ ");
                else if(a[i][j]==2||a[i][j]==4)
                System.out.print("0 ");
                else 
                System.out.print("X ");
              }
              System.out.println("");
            } 
               
              if( a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==1 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==3 ||
                a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==5 ||a[1][3]==a[2][3] && a[2][3]==a[3][3] && a[3][3]==7 )       {
              System.out.println("PLAYER'X' WINS");
              }
               if( a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==1 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==3 ||  
                a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==5 ||a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==7 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if(  a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==3  || a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==3 ||  
                a[3][3]==a[3][2]&&a[3][2]==a[3][1] && a[3][1]==5 || a[1][1]==a[1][2]&&a[1][2]==a[1][3]&& a[1][3]==7)
              {
              System.out.println("PLAYER'X' WINS");
              }
              if(  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==1 ||  a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==3 || 
              a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==5 || a[1][1]==a[2][1]&& a[2][1]==a[3][1]&&a[3][1]==7 )
              {
              System.out.println("PLAYER'X' WINS");
              }
               if(  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==1 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==3 || 
                a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==5 ||  a[3][1]==a[2][2]&&a[2][2]==a[1][3]&&a[1][3]==7)
              {
              System.out.println("PLAYER'X' WINS");
              }
              
          
              
          }
      }


      OUTPUT :

      _  |_  |_  |
      _  |_  |_  |
      _  |_  |_  |
      ENTER THE ROW:
      1
      Enter column
      1
      X _ _ 
      _ _ _ 
      _ _ _ 
      PLAYER '0' CHANCE
      ENTER THE ROW:
      2
      Enter column
      2
      X _ _ 
      _ 0 _ 
      _ _ _ 
      PLAYER 'X' CHANCE
      ENTER THE ROW:
      3
      Enter column
      3
      X _ _ 
      _ 0 _ 
      _ _ X 
      PLAYER '0' CHANCE
      ENTER THE ROW:


      Payroll Management System in java


      • This following program does not contain graphics . This payroll system will work in command prompt or in any java editor.


      PROGRAM :


      import java.util.Scanner;
      public class Payroll {
              
          public static void main(String[] args) {
             
              
         System.out.println("WELCOME TO PAYROLL MANAGEMENT SYSTEM");


          int employeeid,basic,month,i,h,z=0,j;
          double hra,con,med,lta,tot,pf,sal,tds,lic,basic1;
           String name, address;
           Scanner s =new Scanner (System.in);
           System.out.println("Enter the name of employee");
            name= s.next();
            System.out.println("Enter the address of the employee");
            address = s.next();
             System.out.println("enter the employee id");
             employeeid = s.nextInt();
            System.out.println("enter the basic salary of the employee");
            basic= s.nextInt();
           System.out.println("enter the working days of employee in form of month number from 1 to 12");
               month= s.nextInt();
               System.out.println("Enter the value LIC taken by employee:");
               lic= s.nextDouble();
               
               System.out.println("---------------------- REPORT-----------------");
              
               System.out.println("1. ATTENDANCE CHART");
               System.out.println("2. EMPLOYEE DETAILS");
               System.out.println("3. TOTAL ALLOWANCES");
               System.out.println("4. TOTAL DEDUCTION");
               System.out.println("5. MONTHLY SALARY STATEMENT");
               System.out.println("ENTER YOUR CHOICE");
               i= s.nextInt();
               switch(i)
               {
                case 1:
                System.out.println("--------ATTENDANCE CHART---------");
                System.out.println("enter the number of holidays taken by the employee");
                h=s.nextInt();
               if(month==1 || month==3 || month==5||month==7||month==8||month==10||month==12)
                {
                z= 31-h;
                System.out.println("total number of working days were :31");
                System.out.println("employee working days are:" +z);
               
                }
                else if(month==2) {
                z=28-h;
                System.out.println("total number of working days were :28");
                System.out.println("employee working days are:" +z);
                }
                else if(month==4 || month==6 || month==9||month==11){
                z=30-h;
                System.out.println("total number of working days were :30");
                System.out.println("employee working days are:" +z);
                }
                break;
               
                case 2:
                      System.out.println("--------EMPLOYEE DETAILS---------");
                      System.out.println("Employee ID =" +employeeid);
                      System.out.println("Employee name="+name);
                      System.out.println("Employee Address="+address);
                      System.out.println("Employee working days=26");
                      break;
                     
                 case 3:
                    System.out.println("--------TOTAL ALLOWANCE---------");
                    System.out.println("Enter the value LIC taken by employee:");
                    lic= s.nextDouble();
                    System.out.println("Employee id="+employeeid);
                    System.out.println("Employee name = "+name);
                    System.out.println("BASIC SALARY = "+basic);
                    hra = basic * 0.18;
                    System.out.println("HRA = "+hra);
                    con= basic * 0.10;
                    System.out.println(" DA = "+con);
                    med = basic*0.15;
                    System.out.println(" TA = "+med);
                    lta= basic * 0.0175;
                    System.out.println(" ESIC = "+lta);
                    pf = basic * 0.125;
                    System.out.println(" PF = "+pf);
                    tot= basic+hra+con+med+lta-pf-lic;
                    System.out.println("TOTAL SALARY = "+tot);
                    break;
                   
                case 4 :
                  System.out.println("-------- TAX DEDUCTIONS---------");
                  hra = basic * 0.18;
                   
                      con= basic * 0.10;
                   
                    med = basic*0.15;
                   
                    lta= basic * 0.0175;
                   
                    pf = basic * 0.125;
                   
                    tot= basic+hra+con+med+lta;
                    sal = tot*12;
                   if(sal<= 250000)
                   {
                    System.out.println("NO TAX DEDUCTION");
                    }
                    else if(sal>= 250000 && sal<= 500000)
                    {
                    tds= sal*0.05;
                    System.out.println(" TAX DEDUCTION ANUALLY = "+tds);
                   
                    }
                    else if(sal>=500000 && sal<=1000000)
                    {
                    tds = sal*0.10;
                    System.out.println(" TAX DEDUCTION ANNUALY = "+tds);
                    }
                    else if(sal>=1000000)
                    {
                    tds=sal *0.30;
                    System.out.println(" TAX DEDUCTION ANNUALY is = "+tds);
                    }
                    break;
                   
                      case 5 :
                    System.out.println("----------MONTHLY SALARY STATEMENT---------");
                    System.out.println("1. EMPLOYEE WISE");
                    System.out.println("2. TOTAL EMPLOYEE STATEMENT");
                    System.out.println("Enter your choice:");
                    j=s.nextInt();
                    switch(j)
                    {
                    case 1:
                    System.out.println("//////-- EMPLOYEE WISE--//////");
                    System.out.println(" PAYSLIP ");
                    System.out.println("enter the number of holidays taken by the employee");
                h=s.nextInt();
                if(month==1 || month==3 || month==5||month==7||month==8||month==10||month==12)
                {
                z= 31-h;
                System.out.println("total number of working days were :31");
                System.out.println("employee working days are:" +z);
               
                }
                else if(month==2) {
                z=28-h;
                System.out.println("total number of working days were :28");
                System.out.println("employee working days are:" +z);
                }
                else if(month==4 || month==6 || month==9||month==11){
                z=30-h;
                System.out.println("total number of working days were :30");
                System.out.println("employee working days are:" +z);
                }
                   
                    System.out.println("Employee id="+employeeid);
                    System.out.println("Employee name = "+name);
                    System.out.println("BASIC SALARY = "+basic);
                    basic1= basic/30*z;
                    hra = basic1 * 0.18;
                    System.out.println("HRA = "+hra);
                    con= basic1 * 0.10;
                    System.out.println(" DA = "+con);
                    med = basic*0.15;
                    System.out.println(" TA = "+med);
                    lta= basic * 0.0175;
                    System.out.println(" ESIC = "+lta);
                    pf = basic * 0.125;
                    System.out.println(" PF = "+pf);
                    tot= basic1+hra+con+med+lta-pf-lic;
                    System.out.println("TOTAL SALARY = "+tot);
                    break;
                   
                    case 2:
                    System.out.println("------TOTAL EMPLOYEE WISE STATEMENT-----");
                    System.out.println("Total employee in company = 1");
                    hra = basic * 0.18;
                   
                    con= basic * 0.10;
                   
                    med = basic*0.15;
                   
                    lta= basic * 0.0175;
                   
                    pf = basic * 0.125;
                   
                    tot= basic+hra+con+med+lta;
                    sal = tot*12;
                    System.out.println(" salary of employee : "+sal);
                    break;
                   
                    default :
                    System.out.println("wrong choice");
                   
                   
                    }
                    break;
                   
                    default :
                    System.out.println("wrong choice");
                   
                   
               }
               
              
              
              
              
              
          }
      }


      OUTPUT :

      WELCOME TO PAYROLL MANAGEMENT SYSTEM
      Enter the name of employee
      alex
      Enter the address of the employee
      adsdad
      enter the employee id
      2563
      enter the basic salary of the employee
      50000
      enter the working days of employee in form of month number from 1 to 12
      3
      Enter the value LIC taken by employee:
      533
      ---------------------- REPORT-----------------
      1. ATTENDANCE CHART
      2. EMPLOYEE DETAILS
      3. TOTAL ALLOWANCES
      4. TOTAL DEDUCTION
      5. MONTHLY SALARY STATEMENT
      ENTER YOUR CHOICE
      5
      ----------MONTHLY SALARY STATEMENT---------
      1. EMPLOYEE WISE
      2. TOTAL EMPLOYEE STATEMENT
      Enter your choice:
      1
      //////-- EMPLOYEE WISE--//////
       PAYSLIP 
      enter the number of holidays taken by the employee
      6
      total number of working days were :31
      employee working days are:25
      Employee id=2563
      Employee name = alex
      BASIC SALARY = 50000
      HRA = 7497.0
       DA = 4165.0
       TA = 7500.0
       ESIC = 875.0000000000001
       PF = 6250.0
      TOTAL SALARY = 54904.0