Showing posts with label Switch case program. Show all posts
Showing posts with label Switch case program. Show all posts

Saturday, 14 December 2019

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 :


Thursday, 12 December 2019

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 print Fibonacci Series

Program :


class Fibonacci
{
public static void main(String[] args) {
int fs = 10 , a = 0 ,b =1 , c , i ;
System.out.println("Fibonacci Series");

for (i = 1;i<=fs-2 ;i++ )
                 {
                       c= a+b ;

System.out.println(c);

a= b ;

b = c ;
}

}
}

Output :


Wednesday, 11 December 2019

write a java program to print star design.

program :


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

System.out.println("* * * * * *");

System.out.println("* * * * * ");

System.out.println("* * * * ");

System.out.println("* * * ");

System.out.println("* * ");

System.out.println("* ");

}
}

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