I want to make a program that gets a number input and finds the closest perfect square to determine the square length. Thus, the closest perfect square has to be less than the input. For example, if the input is 8, the largest side length of the square is 2. The problem is that the program will ask me to input a number but does not output anything after that. It also says I have a duplicate local variable a1.
import java.util.Scanner;
public class J1 {
public static void main(String[] args) {
int a;
int a1;
Scanner number = new Scanner(System.in);
System.out.println("Number: ");
a = number.nextInt();
int n = (int) Math.sqrt(a1);
/* remove int from a1 */
for ( int a1=a; a1<a; a1--) {
if (Math.floor(a1)==0)
System.out.println("The largest square has side length" + a1);
}
}
}