Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Food Festival at HillTown

HillTown Inn is planning to organize a Food Festival bringing together at one place, a wide variety of cuisines from across the world on account of Christmas. The Hotel Management has rented out a square hall of an indoor Auditorium for this extravaganza. The side of the square hall is y  inches in which a large square table is placed for the display of the most popular and celebrated food items. The side of the square table is x  inches, such that x<y.
 
The Management wanted to fill the remaining floor area with a decorative carpet. To get this done, they needed to know the floor area to be filled with the carpet. Write a program to help the Management find the area of the region located outside the square table but inside the square hall.
 
Input Format:
The first line of the input is an integer y, the side of the square hall.
The second line of the input is an integer x, the side of the square table placed for display.
 
Output Format:
The output should display the area of the floor that is to be decorated with the carpet.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output.]

Sample Input                                                      Output
7                                                                    3

The area to be decorated is 40

Sample Input and Output 2:
5                                                                    2

The area to be decorated is 21


What I have tried:

package demo;

import java.util.Scanner;

public class DemoTranslation {
    public static void main(String[] args) {
        int x, y, z;
        System.out.println("Enter the side of the square hill");
        x = STDIN_SCANNER.nextInt();
        System.out.println("Enter the side of the square table placed for display");
        y = STDIN_SCANNER.nextInt();
        z = x * x - y * y;
        System.out.print("Area to be decorated is " + z);
     }
     public final static Scanner STDIN_SCANNER = new Scanner(System.in);
}
Posted
Updated 19-Feb-22 1:19am

1 solution

Read the question again ...
Quote:
he side of the square table is x inches, such that x<y.
And then look at your code:
z = x * x - y * y;
See your mistake yet?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900