JAVA循环问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
我想把 所有条件都放在WHILE循环里 用下列的思路,方法 实现求解;能实现么?应该怎么做 思路 不能改变 该怎么改WHILE循环里的语句?
public class A1{
public static void main(String[] args){
A2();
}
public static void A2(){
int x=2000;
while(x<=2500&&x%4==0&&x%100==0||x%400==0){
System.out.println(x);
}x++;A2();
}
}
[ 本帖最后由 xe569886048 于 2011-7-8 14:09 编辑 ]
----------------解决方案--------------------------------------------------------
求什么解? 没说清楚!
----------------解决方案--------------------------------------------------------
public class A1{
public static void main(String[] args){
A2(2000);
}
public static void A2(int year){
while(year<=2500&&year%4==0&&year%100==0||year%400==0){
System.out.println(year);
}A2(++year);
}
}
----------------解决方案--------------------------------------------------------
while(year<=2500&&year%4==0&&year%100==0||year%400==0){
System.out.println(year);
}
循环里值没变,所以无限循环 。递归也无限,一般人写不出来。
----------------解决方案--------------------------------------------------------
好像是求闰年,对吗,
----------------解决方案--------------------------------------------------------
没点不解释
----------------解决方案--------------------------------------------------------
写错了哦。
public class A1{
public static void main(String[] args){
A2();
}
public static void A2(){
int x=2000;
while(x<=2500&&x%4==0&&x%100==0||x%400==0){
System.out.println(x);
}x++;A2();
}
}
你这个是求闰年吧、
你的X++不应该放到外面了,这样应该是个死循环了,还有A2();也是多的。
----------------解决方案--------------------------------------------------------
这是个死循环,无解
----------------解决方案--------------------------------------------------------
没看懂问题,
import java.util.Scanner;
public class ruenlian {
public static void main(String[] args){
System.out.println("请输入年份:");
Scanner sc=new Scanner(System.in);
int n =sc.nextInt();
if(n%400==0||n%4==0&&n%100!=0){
System.out.println("这是闰年");
}else{
System.out.println("这不是闰年");
}
}
}
----------------解决方案--------------------------------------------------------
不太懂,菜鸟一个
----------------解决方案--------------------------------------------------------