Java Programming

Dummy ATM Software using Graphical User Interface

import javax.swing.JOptionPane;
public class ATM_Software {
public static void main (String a[])
{
 int i=0;
 while (i!=-1)
{
JOptionPane.showMessageDialog(null,"Built & Designed by Arslan ud Din Shafiq\nCOMSATS Institute of Information Technology,Lahore.\nwww.CWorldbyAS.blogspot.com","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
      JOptionPane.showMessageDialog(null,"WELCOME TO Arslan's Banking ATM","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null,"Insert Your Card & Press OK","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            String pin =  JOptionPane.showInputDialog("Enter your PIN code");
       int pi;
       pi = Integer.parseInt(pin);
       if (pi==1234)
       {
       JOptionPane.showMessageDialog(null, "PIN Code Accepted..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       JOptionPane.showMessageDialog(null, "Now You have ACCESS to Your Account","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
           String sel = JOptionPane.showInputDialog("1>Cash Withdrawl\n2>Bill Payment\n3>Cash Transfer\n4>Balance Inquiry");
           int se;
           se = Integer.parseInt(sel);
           switch (se)
           {
           case 1 :
             String cw  = JOptionPane.showInputDialog("Enter The Amount ");
             int cash;
             cash = Integer.parseInt(cw);
             if (cash%500==0)
             {
             int op =  JOptionPane.showConfirmDialog(null, "Do you really want to withdraw Rs. "+cash);
             if (op==JOptionPane.YES_OPTION)
             {
             JOptionPane.showMessageDialog(null,"You have withdrawn Rs. "+cash+" successfully...!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);

             }
             if (op==JOptionPane.NO_OPTION)
             {
             JOptionPane.showMessageDialog(null, "You don't want to withdraw any amount...");              
             JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                          break;
             }
             if(op==JOptionPane.CANCEL_OPTION)
             {
             JOptionPane.showMessageDialog(null, "You have cancelled the transaction....!! ");              
             JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                 break;
             }
             }
             else if (cash >25000)
             {
             JOptionPane.showMessageDialog(null, "Kindly Enter Amount less than Rs.25000","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             }
             else if (cash <500)
             {
             JOptionPane.showMessageDialog(null, "Kindly Enter Amount more than Rs. 500","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             }
             else if (cash%500 !=0)
             {
             JOptionPane.showMessageDialog(null, "Please enter amount multiple of 500","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             }
             break;
           case 2:
            String selec = JOptionPane.showInputDialog("1>Electricity Bill\n2>Telephone Bill\n3>Gas Bill\n4>Water Bill");
            int selem;
            selem = Integer.parseInt(selec);
            switch (selem)
            {
            case 1:
            String ecus = JOptionPane.showInputDialog("Enter Customer Name");
            String eam = JOptionPane.showInputDialog("Enter Amount");
            int eama;
            eama = Integer.parseInt(eam);
            String ecode = JOptionPane.showInputDialog("Enter Bill Code");
            int ecoda;
            ecoda = Integer.parseInt(ecode);
            String earea = JOptionPane.showInputDialog("Enter Area Name ");
            int con = JOptionPane.showConfirmDialog(null,"You have entered the following information\n\nCustomer Name : "+ecus+"\nAmount"+eama+"\nBill Code : "+ecoda+"\nArea Name :"+earea+"\nIs the above information is correct ? ");
            if (con==JOptionPane.YES_OPTION)
            {
            JOptionPane.showMessageDialog(null,"Your information has been successfully forwarded....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "You have paid Bill of Rs. "+eama,"Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
     
            }
            else if (con==JOptionPane.NO_OPTION)
            {
              JOptionPane.showMessageDialog(null,"Your information has been deleted successfully....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       
            }
            else if (con==JOptionPane.CANCEL_OPTION)
            {
              JOptionPane.showMessageDialog(null,"You have cancelled the process....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            }
            break;
            case 2:
            String tcus = JOptionPane.showInputDialog("Enter Customer Name");
            String tno = JOptionPane.showInputDialog("Enter Telephone No.");
            int inum;
            inum = Integer.parseInt(tno);
            String tam = JOptionPane.showInputDialog("Enter Amount");
            int tama;
            tama = Integer.parseInt(tam);
            String tcode = JOptionPane.showInputDialog("Enter Bill Code");
            int tcoda;
            tcoda = Integer.parseInt(tcode);
            String tarea = JOptionPane.showInputDialog("Enter Area Name ");
            int ton = JOptionPane.showConfirmDialog(null,"You have entered the following information\n\nCustomer Name : "+tcus+"Telephone No. : "+inum+"\nAmount"+tama+"\nBill Code : "+tcoda+"\nArea Name :"+tarea+"\nIs the above information is correct ? ");
            if (ton==JOptionPane.YES_OPTION)
            {
            JOptionPane.showMessageDialog(null,"Your information has been successfully forwarded....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "You have paid Bill of Rs. "+tama,"Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
     
            }
            else if (ton==JOptionPane.NO_OPTION)
            {
              JOptionPane.showMessageDialog(null,"Your information has been deleted successfully....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       
            }
            else if (ton==JOptionPane.CANCEL_OPTION)
            {
              JOptionPane.showMessageDialog(null,"You have cancelled the process....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            }
            break;
            case 3:
            String gcus = JOptionPane.showInputDialog("Enter Customer Name");
            String gam = JOptionPane.showInputDialog("Enter Amount");
            int gama;
            gama = Integer.parseInt(gam);
            String gcode = JOptionPane.showInputDialog("Enter Bill Code");
            int gcoda;
            gcoda = Integer.parseInt(gcode);
            String garea = JOptionPane.showInputDialog("Enter Area Name ");
            int gon = JOptionPane.showConfirmDialog(null,"You have entered the following information\n\nCustomer Name : "+gcus+"\nAmount"+gama+"\nBill Code : "+gcoda+"\nArea Name :"+garea+"\nIs the above information is correct ? ");
            if (gon==JOptionPane.YES_OPTION)
            {
            JOptionPane.showMessageDialog(null,"Your information has been successfully forwarded....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "You have paid Bill of Rs. "+gama,"Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
     
            }
            else if (gon==JOptionPane.NO_OPTION)
            {
              JOptionPane.showMessageDialog(null,"Your information has been deleted successfully....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       
            }
            else if (gon==JOptionPane.CANCEL_OPTION)
            {
              JOptionPane.showMessageDialog(null,"You have cancelled the process....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            }
                       break;
            case 4:
            String wcus = JOptionPane.showInputDialog("Enter Customer Name");
            String wam = JOptionPane.showInputDialog("Enter Amount");
            int wama;
            wama = Integer.parseInt(wam);
            String wcode = JOptionPane.showInputDialog("Enter Bill Code");
            int wcoda;
            wcoda = Integer.parseInt(wcode);
            String warea = JOptionPane.showInputDialog("Enter Area Name ");
            int won = JOptionPane.showConfirmDialog(null,"You have entered the following information\n\nCustomer Name : "+wcus+"\nAmount"+wama+"\nBill Code : "+wcoda+"\nArea Name :"+warea+"\nIs the above information is correct ? ");
            if (won==JOptionPane.YES_OPTION)
            {
            JOptionPane.showMessageDialog(null,"Your information has been successfully forwarded....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "You have paid Bill of Rs. "+wama,"Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
     
            }
            else if (won==JOptionPane.NO_OPTION)
            {
              JOptionPane.showMessageDialog(null,"Your information has been deleted successfully....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       
            }
            else if (won==JOptionPane.CANCEL_OPTION)
            {
              JOptionPane.showMessageDialog(null,"You have cancelled the process....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to pay the bill... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            }

            }
            break;
           case 3 :
            String tus = JOptionPane.showInputDialog("Enter Name of Receiver");
            String tac = JOptionPane.showInputDialog("Enter A/C Number ");
            int ta;
            ta = Integer.parseInt(tac);
            String tm = JOptionPane.showInputDialog("Enter Amount");
            int tma;
            tma = Integer.parseInt(tm);
            String cnic = JOptionPane.showInputDialog("Enter your CNIC Number");
            int nic;
            nic = Integer.parseInt(cnic);
           
            int con = JOptionPane.showConfirmDialog(null,"You have entered the following information\n\nReceiver's Name : "+tus+"\nA/C Number : "+ta+"\nAmount : "+tma+"\nCNIC Number :"+nic+"\nIs the above information is correct ? ");
            if (con==JOptionPane.YES_OPTION)
            {
            JOptionPane.showMessageDialog(null,"Your information has been successfully forwarded....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "You have transfered of Rs. "+tma+" to A/C "+ta,"Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
     
            }
            else if (con==JOptionPane.NO_OPTION)
            {
              JOptionPane.showMessageDialog(null,"Your information has been deleted successfully....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to Transfer Cash... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       
            }
            else if (con==JOptionPane.CANCEL_OPTION)
            {
              JOptionPane.showMessageDialog(null,"You have cancelled the process....","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "Again proceed to Transfer Cash... ","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(null, "Thank You..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
             JOptionPane.showMessageDialog(null, "Take Your Card...","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
               JOptionPane.showMessageDialog(null, "GOOD BYE..!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);

            }
                   break;
           case 4 : 
            JOptionPane.showMessageDialog(null,"Your Current Balance is Rs. 321134","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
           }
       }
       else 
       {
           JOptionPane.showMessageDialog(null, "You have Entered Wrong PIN code..!!!","Built & Designed by Arslan Malik",JOptionPane.ERROR_MESSAGE);
       JOptionPane.showMessageDialog(null,"Thanks...!!!","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
       JOptionPane.showMessageDialog(null,"GOOD BYE","Built & Designed by Arslan Malik",JOptionPane.INFORMATION_MESSAGE);
        JOptionPane.showMessageDialog(null,"TRY AGAIN","Wrong Code",JOptionPane.INFORMATION_MESSAGE);
                break;
   }
}
}
}

Passing constant value to variable


public class variables {
public static void main (String a[])
{
   int x=10;
   {
  System.out.println("I'm Arslan\nI have Rs.");
  System.out.print(x);
   }
}
}

Get three integers from user & find out smallest , largest , sum , average & product of these three numbers.

import java.util.Scanner;
public class sum_product_average_Largest_smallest {
public static void main(String args[]){
Scanner op = new Scanner (System.in);
int a,b,c;
System.out.print("Enter First Integer : ");
a = op.nextInt();
System.out.print("Enter Second Integer : ");
b = op.nextInt();
System.out.print("Enter Third Integer : ");
c = op.nextInt();
int sum;
sum=a+b+c;
System.out.println("Sum is : "+sum);
int product;
product=a*b*c;
System.out.println("Product is : "+product);
double average;
average = sum/3;
System.out.println("Average is : "+average);
if (a<b && a<c)
{
System.out.println("Smallest is :  "+a);
}
if (b<a && b<c)
{
System.out.println("Smallest is : "+b);
}
if (c<a && c<b)
{
System.out.println("Smallest is : "+c);
}
if (a>b && a>c)
{
System.out.println("Largest is :  "+a);
}
if (b>a && b>c)
{
System.out.println("Largest is : "+b);
}
if (c>a && c>b)
{
System.out.println("Largest is : "+c);
}
if (a==b && a==c && b==a && b==c && c==a && c==b)
{
System.out.println("All the Integers are Equal");
}
}
}

Get two numbers from user & sum them

import java.util.Scanner;
public class sum_of_two_numbers {
public static void main (String args[]){
Scanner bucky = new Scanner (System.in);
double fnum,snum,answer;
        System.out.print("Enter First Number : ");
        fnum = bucky.nextDouble();
        System.out.print("Enter Second Number :  ");
        snum=bucky.nextDouble();
        answer = fnum + snum ;
        System.out.println(answer);
}
}

Use for loop to get square & cube from 1 to 10 in java


public class square_cube {
public static void main(String a[]){
int square=1,cube=1,i=0;
System.out.println("Number\tSquare\tCube");
for( i=0 ; i<=10 ; i++ )
{
square = i*i;
            cube = i*i*i;
    System.out.print(i);
        System.out.print("\t");
    System.out.print(square);
        System.out.print("\t");
        System.out.println(cube);
}

}

}

Get a number of 5 digits from user & create spaces between each digit.

import java.util.Scanner;public class spaced_digits { public static void main(String a[]){ Scanner op = new Scanner (System.in); int number,b,c,d,e,f; System.out.print("Enter 5-Digit Number : "); number = op.nextInt(); b = number%10; c = (number/10)%10; d = ((number/10)/10)%10; e = (((number/10)/10)/10)%10; f = ((((number/10)/10)/10)/10)%10; System.out.print(f); System.out.print(" "); System.out.print(e); System.out.print(" "); System.out.print(d); System.out.print(" "); System.out.print(c); System.out.print(" "); System.out.print(b); }}


Get two numbers from user & find out is one number from them is multiple of the other number.

import java.util.Scanner;
public class multiples {
public static void main(String args[]){
Scanner a = new Scanner (System.in);
int x,y;
System.out.print("Enter First Integer : ");
x = a.nextInt();
System.out.print("Enter Second Integer : ");
y = a.nextInt();
if (x%y==0)
{
System.out.println("First is Multiple of Second");
}
else 
{
System.out.println("They are not multiple of each other.");
}
}

}

Convert Letters to Integers(Askey Values)

public class letter_to_integer {
public static void main(String a[]){
char b;
for(b=65;b<127;b++)
{
  System.out.print(""+b);
}
}
}

Hello World


public class helloworld {
 public static void main (String a[])
 {
System.out.println("Hello World...!!!");
 
 }
}

Get Two Numbers From User. Calculate & Print Sum , Subtraction , Division , Multiplication & Modulus using Graphical User Interface

import javax.swing.JOptionPane;
public class graphics_sum {
public static void main(String args[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
                String fn  = JOptionPane.showInputDialog("Enter First Integer : ");
String sn  = JOptionPane.showInputDialog("Enter Second Integer : ");
int num1,num2;
num1 = Integer.parseInt(fn);
num2 = Integer.parseInt(sn);
int sum;
sum = num1+num2;
int sub;
sub = num1-num2;
int div;
div = num1/num2;
                int mul;
                mul = num1*num2;
                 int mod;
               mod = num1%num2;
JOptionPane.showMessageDialog(null,"Sum of Two Entered Integers is "+sum,"Sum of Integers",JOptionPane.INFORMATION_MESSAGE);
       JOptionPane.showMessageDialog(null, "Their Subtraction is "+sub,"Subtraction of Integers",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"Division of Two Entered Integers is "+div,"Division of Integers",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"Multiplication of Two Entered Integers is "+mul,"Multiplication of Integers",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"Modulus of Two Entered Integers is "+mod,"Modulus of Integers",JOptionPane.INFORMATION_MESSAGE);

}


}

Get String From User & Print it on Screen

import java.util.Scanner;
public class getting_input_from_user{
public static void main(String a[])
{
{
          JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
System.out.println("Enter any Line : ");
             Scanner m = new Scanner(System.in);
       System.out.println(m.nextLine());
}
}

}

Graphic User Interface Message Box

import javax.swing.JOptionPane;
public class getprint_name_in_box {
public static void main(String a[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
}
}

Calculate Area of Circle

import javax.swing.JOptionPane;
import java.util.Scanner;
public class Area_of_circle {
public static void main(String args[]){
Scanner a = new Scanner (System.in);
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
int radius;
System.out.print("Enter Radius of Circle : ");
radius = a.nextInt();
double dia;
dia = 2*radius;
System.out.println("\nDiameter is : " +dia);
double cir;
cir = 2*Math.PI*radius;
System.out.println("Circumference of Circle is : " +cir);
double area;
area = Math.PI*radius*radius;
System.out.println("Area of Circle is : " +area);
}

}

Pattern Printing

import javax.swing.JOptionPane;
public class arrow_pattern {
public static void main (String args[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
System.out.println("      *      **********      ***** *****  ");
System.out.println("     ***     *        *    *             *");
System.out.println("    *****    *        *   *               *");
System.out.println("      *      *        *   *               *");
System.out.println("      *      *        *   *              *");
System.out.println("      *      *        *     *           *");
System.out.println("      *      *        *       *       *");
System.out.println("      *      **********          *  *  ");
}

}
Pattern Printing in Dialog Box

import javax.swing.JOptionPane;
public class pattern {
public static void main (String args[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
JOptionPane.showMessageDialog(null,"        *           **********       \n      ***          *             *   \n    *****        *             *   \n      *            *             *   \n      *          *             *   \n      *      *             *     \n      *      *             *     \n      *      **********    ");
}

}

Basic Calculator

import java.util.Scanner;
import javax.swing.JOptionPane;
public class basic_calculator {
public static void main (String args[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
double a,b;
Scanner x = new Scanner (System.in);
System.out.println("Enter First Number ");
a = x.nextDouble();
System.out.println("Enter Second Number : ");
b = x.nextDouble();

double sum;
sum = a+b;
System.out.println("Addition is "+sum);
double sub;
sub = a-b;
System.out.println("Subtraction is "+sub);
double mul;
mul = a*b;
System.out.println("Multiplication is "+mul);
double div;
div = a/b;
System.out.println("Division is "+div);
double mod;
mod = a%b;
System.out.println("Modulus is  "+mod);
}
}

Addition , Subtraction , Multiplication , Division
Modulus of Two Constant Numbers

import javax.swing.JOptionPane;
public class calculation_of_two_constant_numbers {

public static void main (String a[])
{
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
double x=50,y=30,sum,sub,div,mul,mod;
{
sum=x+y;
{
System.out.print("Addition is : ");
System.out.println(sum);
}
sub=x-y;
{
System.out.print("Subtraction is : ");
System.out.println(sub);
}
mul=x*y;
{
System.out.print("Multiplication is : ");
System.out.println(mul);
}
div=x/y;
{
System.out.print("Division is : ");
System.out.println(div);
}
mod=x%y;
{
System.out.print("Modulus is : ");
System.out.println(mod);
}

}
}
}

Get Two Integers from user & give comparison
such that 1st>2nd or 1st<2nd or 1st=2nd

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Comparing_two_integers {
public static void main(String args[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
Scanner pis = new Scanner(System.in);
int a,b;
System.out.print("Enter First Integer : ");
a = pis.nextInt();
System.out.println("Enter Second Integer : ");
b = pis.nextInt();
if (a<b)
{
System.out.print("First < Second");
}
if (a>b)
{
System.out.print("First > Second");
}
if (a==b)
{
System.out.print("First = Second");
}
}
}

Count Positive Numbers , Negative Numbers & Zeros
Entered by User using if selection statement

import java.util.Scanner;
import javax.swing.JOptionPane;
public class counting_positive_negative_numbers {
public static void main(String a[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
Scanner op = new Scanner(System.in);
int neg=0,pos=0,zero=0;
int num1=0,num2=0,num3=0,num4=0,num5=0;
System.out.print("Enter First Number : ");
num1 = op.nextInt();
System.out.print("Enter Second Number : ");
num2 = op.nextInt();
System.out.print("Enter Third Number : ");
num3 = op.nextInt();
System.out.print("Enter Fourth Number : ");
num4 = op.nextInt();
System.out.print("Enter Fifth Number : ");
num5 = op.nextInt();
if (num1<0)
{
  neg++;
}
if (num2<0)
{
  neg++;
}
       if (num3<0)
{
  neg++;
}
       if (num4<0)
{
  neg++;
}
       if (num5<0)
{
  neg++;
}

  if (num1>0)
   {
  pos++;
   }
  if (num2>0)
   {
  pos++;
   }
  if (num3>0)
   {
  pos++;
   }
  if (num4>0)
   {
  pos++;
   }
  if (num5>0)
   {
  pos++;
   }
  if (num1==0)
      {
      zero++;
      }
  if (num2==0)
    {
      zero++;
    }
  if (num3==0)
    {
      zero++;
    }   
  if (num4==0)
    {
      zero++;
    }   
  if (num5==0)
    {
      zero++;
    }   
   System.out.println("Number of Negative Integers is : "+neg);
   System.out.println("Number of Positive Integers is : "+pos);
   System.out.println("Number of Zero Integers is     : "+zero);
}
}

Get Number from user & check
whether it is Even or Odd

import java.util.Scanner;
import javax.swing.JOptionPane;
public class even_odd {
public static void main(String args[]){
JOptionPane.showMessageDialog(null,"© Built & Designed by Arslan Malik™\nCOMSATS Institute of Information Technology, Lahore.\nwww.CWorldbyAS.blogspot.com");
Scanner a = new Scanner (System.in);
int b;
System.out.println("Enter Any Number : ");
b = a.nextInt();
if (b%2==0)
{
System.out.println("You have entered EVEN number.");
}
else
{
System.out.println("You have entered ODD number.");
}
}

}


1 comment: