Can u pls explain to me the details of this program? how did it come up to this, the uses of each part
import java.util.Scanner;
public class Activity3 {
public static void main(String[] args) {
System.out.println(two(5,3));
}
public static int one(int x, int y) {
return x > y ? x + y : x - y * 2;
}
public static double two(int x, double a) {
Scanner in = new Scanner(System.in);
int first = one(6, 8);
double z = in.nextDouble();
z += a;
first += x;
return z > first * 2 ? z : 2 * first - z;
}
}
package activity3;
import java.util.Scanner;
//This is the class Activity3
public class Activity3 {
//The main function
public static void main(String[] args) {
System.out.println(two(5,3)); //Calling the two function
}
public static int one(int x, int y) {
return x > y ? x + y : x - y * 2; // Returns x+y if x>y else returns x-y *2
}
public static double two(int x, double a) {
Scanner in = new Scanner(System.in);
int first = one(6, 8); //Calling the one() function above
double z = in.nextDouble(); //Getting a number from a user.
z += a; //Adding the number entered by the user to a, one of the parameters that the functions take
first += x; //Adding x and first, the results of one function
return z > first * 2 ? z : 2 * first - z;
// Returning z if z id greater than (first *2) otherwise the function will return first - z
}
}
Comments
Leave a comment