mubashir
java beginnerssss!!!
1 Answer(s)      6 years ago
Posted in : Java Beginners

write a program in java that check two values rather it is even or odd if both entries are even then multiply both vaalue and if both are odd then bigger term minus from lesser and if one even and one entry is odd then the msg display is wrong entry

Ads

View Answers

October 21, 2010 at 10:53 AM


Hi Friend,

Try the following code:

import java.util.*;
class CheckTwoValues{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter value1: ");
        int num1=input.nextInt();
        System.out.println("Enter value2: ");
        int num2=input.nextInt();
        if((num1%2==0)&&(num2%2==0)){
            int multiply=num1*num2;
            System.out.println(multiply);
        }
        else if((num1%2!=0)&&(num2%2!=0)){
            int subtract=0;
            if(num1>num2){
            subtract=num1-num2;
            System.out.println(subtract);
            }
            else{
                subtract=num2-num1;
                System.out.println(subtract);
            }
        }
        else{
            System.out.println("Wrong Entry!");
        }
        }
}

Thanks










Related Tutorials/Questions & Answers:

Ads

Advertisement