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


Thursday, 12 December 2019

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 create character variables color , and output red if variable r = Red , b = Blue , g = Green else output is ERROR using SwitchCase.

program :

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

char color = 'r' ;
switch(color)
{
case 'R':
System.out.println(" Red ");
break ;

case 'B' :
System.out.println(" Blue");
break ;

case 'G' :
System.out.println("Green") ;
break ;

default :
System.out.println(" Error") ;
break ;
}
}
}


Output :





Write a Java program to calculate a square and cube of Integer

Program :


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

int x = 2 ;
int sqrt ;

sqrt = x*x ;
int cube ;
cube = x*x*x ;

  System.out.println(" Square is "+sqrt);

  System.out.println("Cube is "+cube);
}
}

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