Showing posts with label Arithmatic Operation. Show all posts
Showing posts with label Arithmatic Operation. Show all posts

Saturday, 14 December 2019

Write a java program to swap a two integer without using a Temporary Third variable

Program :
class Swap1
{
    public static void main(String[] args) {
       
        int x = 5 ;
        int y = 7 ;

        x = x +  y ;
        y =  x - y ;
        x = x - y ;

        System.out.println("After Swapping " +x);
        System.out.println("Before Swapping " +y);

    }
}

Output :


Friday, 13 December 2019

write a java program to demonstrate used of Math Function pow()

Program :

import java.lang.Math ;
public class Power
{
    public static void main(String[] args) {
        double n1 = 2 , n2 = 3;

        System.out.println(+n1 + " ^ " + n2 + " = " +Math.pow(n1 , n2 ));
    }
}

Output :


write a java program to find the smallest of two value using Math Function min()

Program :

import java.lang.Math ;
public class Minimum
{
    public static void main(String[] args) {
        int n1 , n2 ;

n1 = 3 ;
n2 = 4 ;

        System.out.println("Manimum of " + n1 +" and " + n2 + " is " + Math.min(n1 , n2)) ;

    }
}

Output :



write a java program to find the largest of two value using Math Function max()

Program :

import java.lang.Math ;
public class Maximum
{
    public static void main(String[] args) {  
 
        int n1 , n2 ;

        n1 = 3 ;
        n2 = 4 ;

        System.out.println("Maximum of " + n1 +" and " + n2 + " is " + Math.max(n1 , n2)) ;

    }
}

Output :


write a java program to demonstrate increment and decrement Operator

 Program :

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

        int a , b ;

        a = 2 ;
        b = 3 ;

        a++ ;
        ++a ;
        System.out.println("Value of after increment " +a) ;

        --b ;
        b-- ;
        System.out.println("Value of after decrement " +b) ;
    }
}


Output :


write a java program to accept the value of radius from user and calculate area of circle and display it using Scanner class.

Program :

import java.util.Scanner;
class Circle
{
    public static void main(String[] args) {
        double rad , a ;
Scanner sc = new Scanner (System.in) ;

System.out.println(" Enter Radius : ");
        rad = sc.nextFloat();

a = 3.14 * rad * rad;
        System.out.println("Area of Circle is  : "+a);

    }
}

Output :


Write a java program to input marks of 5 student if 5 subject out of 100 marks each , output sum and percentage of marks and appropriate division i.e distigusion first class upto fail

Programe : import java.util.*; class Student { public static void main(String args[])     {     Scanner s = ...