Home Answers Viewqa Java-Beginners java beginnerssss!!!

 
 


mubashir
java beginnerssss!!!
1 Answer(s)      2 years and 7 months 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

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.