Showing posts with label java language. Show all posts
Showing posts with label java language. Show all posts

Friday, June 5, 2020

Write a program in java to find Smallest Number in three number using if else statement.

12)  Write a program in java to find Smallest Number in three number using if else statement.

import java.util.*;

public class Smaller_in_three_using_if_else

{

     public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter three numbers");

        int a = sc.nextInt();

        int b = sc.nextInt();

        int c = sc.nextInt();

        if(a<b&&a<c)

        {

             System.out.println("Smaller number = "+a);

        }

        else if(b<a&&b<c)

        {

            System.out.println("Smaller number = "+b);

        }

        else

        {

            System.out.println("Smaller number = "+c);

        }

    }

}


Write a program in java to find Greatest Number in three number using if else statement.

11)  Write a program in java to find Greatest Number in three number using if         else statement.

import java.util.*;
public class Greater_in_three_using_if_else
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter three numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a>b&&a>c)
        {
             System.out.println("Greater number = "+a);
        }
        else if(b>a&&b>c)
        {
            System.out.println("Greater number = "+b);
        }
        else
        {
            System.out.println("Greater number = "+c);
        }
    }

}


Write a program in java to input a number and check whether it is Buzz Number or not?(n%10==7 ||n%7==0)

10)  Write a program in java to input a number and check whether it is Buzz Number or not?(n%10==7 ||n%7==0)

import java.util.*;
public class Buzz_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a numbers");
        int a = sc.nextInt();
        if(a%10==7||a%7==0)
        {
            System.out.println("Entered number is a buzz number ");
        }
        else
        {
             System.out.println("Entered number is not a buzz number ");
        }
    }
}

Write a program in java to input a number and check whether it is Even or Odd?

9)  Write a program in java to input a number and check whether it is Even or Odd?

import java.util.*;
public class Even_Odd
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a numbers");
        int a = sc.nextInt();
        if(a%2==0)
        {
            System.out.println("Entered numbeer is even");
        }
        else
        {
            System.out.println("Entered numbeer is odd");
        }
    }
}

Thursday, June 4, 2020

Write a program in java to input two numbers and find the Smaller Number using conditional operator.

8)  Write a program in java to input two numbers and find the Smaller Number using conditional operator.

import java.util.*;
public class Smaller_using_conditional_operator
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = (a<b)?a:b;
        System.out.println("Smaller num = "+c);
    }
}

Write a program in java to input two numbers and find the Greater Number using conditional operator.

7)  Write a program in java to input two numbers and find the Greater Number using conditional operator.

import java.util.*;
public class greater_using_conditional_operator
{
    public static void main( String args [ ] )
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = (a>b)?a:b;
        System.out.println("Greater num = "+c);
    }
}

Write a program in java to input two numbers and find the Smaller Number using if else.

6)  Write a program in java to input two numbers and find the Smaller Number using if else.

import java.util.*;
public class Smaller_using_if_else
{
    public static void main( String args[ ] )
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b)
        {
             System.out.println("Smaller number = "+a);
        }
        else
        {
            System.out.println("Smaller number = "+b);
        }
    }
}

Write a program in java to input two numbers and find the Greater Number using if else.

5)  Write a program in java to input two numbers and find the Greater Number using if else.

import java.util.*;
public class Greater_using_if_else
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>b)
        {
            System.out.println("Greater number = "+a);
        }
        else
        {
            System.out.println("Greater number = "+b);
        }
    }
}

Write a program in java to input a number and check whether it is Positive or Negative or Neutral?

4)  Write a program in java to input a number and check whether it is Positive or Negative or Neutral?

public class positive_negative_neutral
{
   public static void main(int a)
   {
       if(a>0)
       {
           System.out.println("positive");
       }
       else if(a<0)
       {
           System.out.println("Negative");
       }
       else if(a==0)
       {
           System.out.println("Neutral");
        }
    }
}

Write a program in java to input two number and Swap the Numbers (interchange the value) without using third variable.

3)  Write a program in java to input two number and Swap the Numbers (interchange the value) without using third variable.

public class Swaping_without_using_third_var
{
    public static void main(int a,int b)
    {
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        a = a + b;
        b = a - b;
a = a - b;
        System.out.println();
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
}


Write a program in java to input two number and Swap the Numbers (interchange the value) using third variable.

2)  Write a program in java to input two number and Swap the Numbers (interchange the value) using third variable.

public class Swaping_using_third_var
{
    public static void main(int a, int b)
    {
        System.out.println("a = "+a);
        System.out.println("b = "+b);
        int p = a;
        a = b;
        b = p;
        System.out.println();
        System.out.println("a = "+a);
        System.out.println("b = "+b);
    }
}

Write a program in java to show the how to generate Random Number in any program?

1)  Write a program in java to show the how to generate Random Number in any program?

public class Random_number
{
    public static void main(String args[])
    {
        double a=Math.random();
        System.out.println("a = "+a);
    }
}

 jhvghvgk ;nkjn ,nkjhj