Answer to Question #278118 in Java | JSP | JSF for 543654

Question #278118

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;

  }

}


1
Expert's answer
2021-12-10T13:22:10-0500
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


  }


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS