I need to make a program that uses two different methods. The first method adds a + b + c = d whilst the second adds x + y = z. Then it has to print out d and z as well as the sum of d + z. The program has to take input from the user.
I know that you can't call variables outside of their methods, so is there any workaround to this? It has to follow the instructions I previously stated
I'm missing the part where I add d and z, this is my current program:
import java.util.Scanner;
public class myProgram {
static void methodAB(){
Scanner myScan = new Scanner(System.in);
System.out.println("Enter A: ");
float A = myScan.nextFloat();
System.out.println("Enter B: ");
float B = myScan.nextFloat();
System.out.println("Enter C: ");
float C = myScan.nextFloat();
float D = A + B + C;
System.out.println("Sum of MethodAB: " + D);
}
static void methodXY(){
Scanner myScan = new Scanner(System.in);
System.out.println("Enter X: ");
float X = myScan.nextFloat();
System.out.println("Enter Y: ");
float Y = myScan.nextFloat();
float Z = X + Y;
System.out.println("Sum of MethodXY: " + Z);
}
public static void main(String[] args) {
methodAB();
methodXY();
//this is the part im stuck on
//i cant call variables d and z so i cant add them together
}
}
just return them and then add