Write code in Java to do the following task Make sure you ha
Write code in Java to do the following task. Make sure you have no errors of syntax or logic. Save and run it to make sure. (10 pts.)
Task: add two numbers “x” and “y”. If their sum is 3 then make another number “z” equal to that sum, otherwise “z” is zero. Do this for two instances: once when “x” is 1 and “y” is 2, and another when both “x” and “y” are 2.
Solution
Answer:
class ass
{
int z=0;
void cal(int a,int b)
{
z=a+b;
if(z==3)
{
System.out.println(\"z=\"+z);
}
else
{
z=0;
System.out.println(\"z=\"+z);
}
}
}
class elixir
{
public static void main(String[] args)
{
int a=2,b=3;
ass a1=new ass();
System.out.println(\"\ \ value of x=1 and y=2\");
a1.cal(1,2);
System.out.println(\"\ \ changed the value of x=2 and y=2\");
a1.cal(2,2);
}
}

