Sunday, July 16, 2017

Given the following pseudo code, write a program that executes it.

Pseudocode

a. read x

b. read y

c. compute p=x*y

d. compute s=x+y

e. total=s2+p*(s-x)*(p+y)

f. Print total




/**
 * Created by Jo on 7/10/2017.
 * For more exercises and lessons, visit http://shegertech.blogspot.com/
 * Chapter 3, Exercise 1
 */

import java.util.Scanner;
public class Q1Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        float x;
        float y;
        float p;
        float s;
        float total;
        System.out.print("Enter x value : ");
        x= in.nextFloat();

        System.out.print("Enter y value : ");
        y = in.nextFloat();
        System.out.print("\n");
        p=x*y;
        s=x+y;
        total=s*s+p*(s-x)*(p+y);
        System.out.print("Total : "+total);
        System.out.print("\n");


    }
}

Share: