PeakNotes - Your Ultimate Resource for Coding Tips and Tutorials

java programing lab

     

 


Que 1. arithmetic 


   Ans

         class arithmatic

{

    public static void main(String args[])

    {

        int a=10;

        int b=5;

       

        // addition

        int c=a+b;

        System.out.println("sum is :"+c);

 

        //subtract

        int d=a-b;

        System.out.println("subtract is :"+d);

 

        //multiply

        int e=a*b;

        System.out.println("multiply is :"+e);

 

        //divide

        int f=a/b;

        System.out.println("divide is :"+f);

    }


output

sum is :15

subtract is :5

multiply is :50

divide is :2 



Que 2 area of square 

ans

class square

{

    public static void main(String args[])

    {

        int a=5;

        int c=a*a;

 

        System.out.println("the area of square is :"+c);

    }

}

output

the area of square is :25




Que 3 area of  triangle 

ans

class triangle

{

    public static void main (String args[])

    {

        int h=10;

        int b=5;

        double c=0.5*h*b;

 

        System.out.println("the are of triangle is:"+c);

    }   

}

output

the are of ractangle is:25.0



Que 4 area of ractangle

ans

class ractangle

{

    public static void main (String args[])

    {

        int l=10;

        int b=10;

        int c=l*b;

 

        System.out.println("the are of ractangle is:"+c);

    }

}

output

the are of ractangle is: 100

Que 5 area of circle

ans

class circle

{

   public  static void main(String args[])

   {

    double  a=3.14 ;

    int r=3 ;

    double  c=a*r*r ;

    System.out.println("The area of circle :"+c) ;

   

   }   

}

output

The area of circle :28.259999999999998


 

Que 6 swap two no. 

ans

public class swap

{

    public static void main(String args[])

    {

        int a=10;

        int b=5;

 

        System.out.println("\nBefore swaping \n");

        System.out.print("a="+a);

        System.out.print("\nb="+b);

 

        int c=a;

        a=b;

        b=c;

 

        System.out.println("\n \nAfter swaping \n");

        System.out.print("a="+a);

        System.out.print("\nb="+b);

    }

   

}


output

Before swaping

 

a=10

b=5

 

After swaping

 

a=5

b=10


Que 7. wap to add two no. using command line argument

class p8 {
    public static void main(String args[])
    {
        int a,b,c;
        a=Integer.parseInt(args[0]);
        b=Integer.parseInt(args[1]);
        c=a+b;
        System.out.println(" the sum is :"+c);
    }
}

   

output 

the sum is 33


Que 8. wap to calculate area of circle using comm. line args?

class Cie {
    public static void main(String args[])
    {
        double a, c;
        a=Integer.parseInt(args[0]);
        c=a*a*3.14;

        System.out.println("the area is : "+c);
    }
}


Output

the area of Circle is :78.4


Que 9. wap to calculate area of Rectangle Using command line args?

class Re {
       public static void main(String args[])
    {
        int a, b, c;
        a=Integer.parseInt(args[0]);
        b=Integer.parseInt(args[1]);
        c=a*b;
        System.out.println("The sum is :"+c);

    }

}


Output

the area of Rectangle is: 30

Que 10. Wap to Check whether number is even or odd.

class pro9
{
    public static void main(String args[])
    {
        int n;
        n=Integer.parseInt(args[0]);

        if(n%2==0)
        System.out.println("even");
        else
        System.out.println("odd");
    }
}

Output

number is even 

Que. 11 write a program to use final variable.

class prog11
{
 
    public static void main(String args[])
    {
        final int a=10;
        a=a+10;
        System.out.println("a="+a);
    }

}

output 

error: cannot assign a value to final variable a





Que. 12 write a program to calculate area of circle using method (function) 

class prog12
{
        public void calculate1(double r)
        {
            final double pi=3.14;
            double area=pi*r*r;
            System.out.println("Area of the circle is "+area);
        }

        public static void main(String args[])
        {
            prog12 p=new prog12();
            double r=Double.parseDouble(args[0]);
            p.calculate1(r);
        }
   
}

output

input  5

Area of the circle is 78.5





Post a Comment

0 Comments