Tile Game: In connection to the National Mathematics Day celebration, the Regional Mathematical Scholars Society had arranged for a Mathematics Challenge Event where school kids participated in large number. Many interesting math games were conducted, one such game that attracted most kids was the tile game where the kids were given ‘n’ square tiles of the same size and were asked to form the largest possible square using those tiles.
Help the kids by writing a program to find the area of the largest possible square that can be formed, given the side of a square tile (in cms) and the number of square tiles available.
Input Format:
First line of the input is an integer that corresponds to the side of a square tile (in cms).
Second line of the input is an integer that corresponds to the number of square tiles available.
Output Format:
Output should display the area of the largest possible square that can be formed (in square cms) with the available tiles.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output.]
Sample Input:
5
8
Sample Outpu:
100
Solution
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
int n = sc.nextInt();
int i = 1;
int m = 0;
int a = 0;
while(i*i <= n){
m = i*i;
i++;
}
a = m*(l*l);
System.out.println(a);
}
}
Happy Learning – If you require any further information, feel free to contact me.