Showing posts with label fibonacci series. Show all posts
Showing posts with label fibonacci series. 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 :


Write a java program to swap a two integer using third variable Temporary.

Program :

class Swap
{
    public static void main(String[] args) {
       
        int x = 5 ;
        int y = 7 ;
        int temp ;
        temp = x ;
        x = y ;
        y = temp ;

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

    }
}

Output :


Friday, 13 December 2019

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 find the greatest among Three Number

 Program :

class GreatestThree
{
    public static void main(String[] args) {
        int x = 5 , y = 7 , z = 9 ;

if(x > y && x > z)
System.out.println("x is Greatest");

else
            if(y > x && y > z)
System.out.println("Y is Greatest");

else
System.out.println("Z is Greatest");   
        }
    }

Output :


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

 Program :

import java.lang.Math ;
public class Expo
{
    public static void main(String[] args) {
        System.out.println("Exponential       Value of 709.7822 is"+Math.exp(709.7822)) ;
    }
}

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 perform basic Arithmatic Operation using Arithmatic Operator

Program :

class Arithmatic
{
    public static void main(String[] args) {
        int a = 5 , b = 2 ;
        int sum , sub , mul , mod ;
        float div ;

        sum = a + b ;
        System.out.println("Sum is "+sum);

sub = a - b ;
        System.out.println("Subtraction is " +sub);

mul = a * b ;
        System.out.println("Multiplication is " +mul);

div = a / b ;
        System.out.println("Division is "+div);

mod = a % b ;
        System.out.println("Mod is "+mod);
           }
}

Output :




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

Program :

import java.lang.Math ;
public class Absolute
{
    public static void main(String[] args) {

        int x = -2 ;

        System.out.println("original Value = " +x) ;
System.out.println("Absolute Value = " +Math.abs(x));
}
}


Output :


Thursday, 12 December 2019

Write a java program to calculate sum of digit .

Program :

class Sum
{
public static void main(String[] args) {
int x = 123 , Sum = 0 ;

int rem ;
while(x>0)
{
rem = x%10 ;

Sum = Sum + rem ;

x = x/10 ;
}

System.out.println("Sum is "+Sum);
}
}

Output :


Write a java program to calculate SquareRoot of a given number.

Program :


import java.lang.Math;
class SquareRoot
{
public static void main(String[] args) {

               double x = 5 ;

               double y ;

               y = Math.sqrt(x);

               System.out.println("Y = " +y);
}
}

Output :


write a java program to check the given No is Prime or Not.

Program :


class Prime
{
public static void main(String[] args) {
int n = 7 , i = 1 , count = 0 ;
do
{
if (n % i == 0) 

count++ ;

i++ ;

}while( i<=n);

if (count == 2 ) 
System.out.println("It is a Prime Number ");

else
System.out.println("It is not a Prime Number ");

          }

}

Output :


write a java program to check the given number is palindrome or not.

Program :


class Palindrome
{
public static void main(String[] args) {
int n = 123 ;

int p = n , s = 0 ;
while(n>0)
{
int z  = n%10 ;

s = (s*10) + z ;

n = n/10 ;
}

if (s == p)

System.out.println("It is a Palindrome " +s);

System.out.println("It is not a Palindrome " +s);
}

}

Output :


write a java program to find the greatest number among 2 digit.

program :


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

if (x > y ) {

System.out.println(" Greatest Number is " +x);
}

else{

System.out.println("Greatest Number is " +y);
}
}
}

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 = ...