Sunday, June 7, 2020

Write a program to input two numbers and check whether it is Even or Odd without using if else.

15)  Write a program in java to input two numbers and check whether it is Even or Odd     without using if else.

import java.util.*;
public class even_odd_without_ifelse
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        String s = (a%2==0)?"EVEN":"ODD";
        System.out.println("Entered number is "+s);
    }
}

Friday, June 5, 2020

Write a program in java to find Smallest Number in three number using conditional operator.

14)  Write a program in java to find Smallest Number in three number using   conditional operator.

import java.util.*;
public class Smaller_in_three_using_conditional_operator
{ 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();
        int d = (a<b) ? (a<c)?a:c : (b<c)?b:c ;
        System.out.println("Smaller num = "+d);
    }
}

Write a program in java to find Greatest Number in three number using conditional operator.

13)   Write a program in java to find Greatest Number in three number using       conditional operator.

import java.util.*;

public class greater_in_three_using_conditional_operator

{

    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();

        int d = (a>b)? (a>c)?a:c : (b>c)?b:c ;

        System.out.println("Greater num = "+d);

    }

}

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");
        }
    }
}

 jhvghvgk ;nkjn ,nkjhj