Computer Science, asked by indrakshidas3, 7 months ago

write a program in java to find the sum, difference and product of two given numbers 45 and 55. Also write the variable list for the same.

please answer​

Answers

Answered by armaanaujla1404
11

Explanation:

class abc

{

public static void main string args[]

{

int a= 45, int b=55,sum,diff,pro

sum= a+b

system.out.printline(sum)

diff=a-b

system.out.printline(diff)

pro=a*b

system.out.printline(pro)

}

}

HOPE THIS WILL HELP YOU

Answered by Pridhavstar
2
For sum of even Number :
public class even{
public static void main(String []args){
int sum = 0;
for(int i=1;i<=55;i++){
if(i%2==0){
sum = sum + i;
}
}
System.out.println(sum);
}
}
Modification for sum of odd:
change the condition of if statement:
i%2==1 instead of i%2==0
Explanation:
create the main function and declare the variable with zero.
Then, take a for loop for traversing the number from 1 from 55.
Inside the for loop, if statement check the condition for even number
A number is even if number divide by 2 and give zero reminder.
so, number%2==0 it is the condition for even number.
then add the even number until condition TRUE.
and finally print the result.
Modification for sum of odd number:
A number is odd, if number divide by 2 and give one reminder.
it means, number%2==1 it is the condition for odd number.
just change the if condition with above.
Similar questions