如何使用來自不同while循環的變量並將它們插入到打印語句中?使用來自兩個不同while循環的變量
public class Squares{
public static void main (String [] args){
int counterA = 0;
int counterB= 0;
while (counterA<51){
counterA++;
if (counterA % 5 == 0){
int one = (counterA*counterA);
}
}
while (counterB<101){
counterB++;
if (counterB % 2 == 0){
int two = (counterB*counterB);
}
}
System.out.println(one+two);
}
}
我只得到一個線的時候我應該得到一些 – jenncar
是什麼你真的想要做什麼?發佈你的問題陳述? –
您的打印聲明只會執行一次。考慮在循環內移動它。 – Zavior