用java写一个表达式

thatsinteresting 2010-03-26 10:41:42
c语言的形式如下:
main(){
int a;
scanf("%d",&a);
printf(a%(a%100?4:400)?"NO":"YES");
}

怎么样用java表示出类似的形式。。。
...全文
127 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
daodaowh 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 keeya0416 的回复:]
引用 3 楼 goldenfish1919 的回复:
Java code

public static void main(String args[])throws Exception{
String line= System.console().readLine();
int a=Integer.parseInt(line);
System.out.println(a%(a%10…………
[/Quote]

keeya0416 2010-03-26
  • 打赏
  • 举报
回复
求闰年的话 应该是
i%(i%100 == 0? 400 : 4 ) == 0 ? “YES”: “NO”;
keeya0416 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 goldenfish1919 的回复:]
Java code

public static void main(String args[])throws Exception{
String line= System.console().readLine();
int a=Integer.parseInt(line);
System.out.println(a%(a%10……
[/Quote]
再来个异常处理就完美了。

不过楼主是不是要求是否闰年啊
感觉逻辑有点问题;
a%(a%100==0?4:400)==0?"NO":"YES"
如 a = 2001;
a%100==0?4:400 返回的是 400;
2001%400 != 0, 最后判断 2001 是闰年

a = 2002,2003,2004 都是闰年?
Ark032425 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 goldenfish1919 的回复:]
Java code

public static void main(String args[])throws Exception{
String line= System.console().readLine();
int a=Integer.parseInt(line);
System.out.println(a%(a%10……
[/Quote]
差不多就这样
若鱼1919 2010-03-26
  • 打赏
  • 举报
回复

public static void main(String args[])throws Exception{
String line= System.console().readLine();
int a=Integer.parseInt(line);
System.out.println(a%(a%100==0?4:400)==0?"NO":"YES");
}
knightzhuwei 2010-03-26
  • 打赏
  • 举报
回复
输入输出不需要了吧
knightzhuwei 2010-03-26
  • 打赏
  • 举报
回复
a%(a%100>0?4:400)>0?"NO":"YES"
l_binq 2010-03-26
  • 打赏
  • 举报
回复
import java.util.Scanner;
public class TestInJava {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
System.out.println(a%(a%100?4:400)?"NO":"YES");
}
}
hepeng_8 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 daodaowh 的回复:]
引用 5 楼 keeya0416 的回复:
引用 3 楼 goldenfish1919 的回复:
Java code

public static void main(String args[])throws Exception{
String line= System.console().readLine();
int a=Integer.parseInt(line);
Syste……
[/Quote]
longmei998 2010-03-26
  • 打赏
  • 举报
回复
看看怎么用的
dhysf 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 knightzhuwei 的回复:]
输入输出不需要了吧
[/Quote]
顶!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧