这是一个程序,用于查明某人的年龄应该是一年中的平方根。我如何从这个循环中选择一个年龄和关联年份,以便我可以打印它?从循环中取值?
package squareAges;
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.lang.Math;
public class SquareAges {
public static final int MIN_YEAR = 1893;
public static final int MAX_YEAR = 2139;
public static void main(String[] args) {
for (int age = 0; age <= 123; age++) {
System.out.println(age + "= " + age * age + " ");
if (MIN_YEAR <= (age * age) && (age * age) <= MAX_YEAR) {
JOptionPane.showMessageDialog(null, "It is possible that someone alive today "
+ "has, is, or will be alive in a year that is the square of their age.");
}
}
}
}
谢谢。
申报INT sqrtAge = 0之外for循环,然后指定sqrtAge = age * age;在里面 – fabricio
我期待从循环中获取特定的价值(例如)年龄45 =年2025年 –