软件测试闰年平年代码,软件测试——闰年测试

importjavafx.application.Application;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.Scene;importjavafx.scene.control.Button;importjavafx.scene.control.TextField;importjavafx.scene.layout.AnchorPane;importjavafx.scene.text.Text;importjavafx.stage.Stage;public class test2 extendsApplication {public static voidmain(String[ ] args) {

test2.launch( args );

}public voidstart( Stage primaryStage ) {

primaryStage.setTitle("input testing");

AnchorPane root= newAnchorPane();

Text text= new Text("请输入测试年份");final Text textans1 = new Text("");final TextField intext1 = new TextField("");

intext1.setMaxSize(140, 20);

AnchorPane.setTopAnchor(text,40.0);

AnchorPane.setLeftAnchor(text,100.0);

AnchorPane.setTopAnchor(textans1,120.0);

AnchorPane.setLeftAnchor(textans1,70.0);

AnchorPane.setTopAnchor(intext1,60.0);

AnchorPane.setLeftAnchor(intext1,70.0);

root.getChildren().addAll(text,intext1);

root.getChildren().addAll(textans1);

Button btn= new Button("提交");

root.getChildren().addAll(btn);

AnchorPane.setTopAnchor(btn,90.0);

AnchorPane.setLeftAnchor(btn,120.0);

btn.setOnAction(new EventHandler() {public voidhandle(ActionEvent arg0) {

textans1.setText(check(intext1.getText().toString()));

}

});

primaryStage.setScene(new Scene(root,300,200));

primaryStage.show( );

}publicString check(String str){try{int year =Integer.parseInt(str);if(year <0)return "请输入正确年份";if(year % 100 ==0){if(year % 400 == 0)return str+"是闰年";

}else{if(year % 4 == 0)return str+"是闰年";

}

}catch(Exception e){return "非法输入";

}return str+"不是闰年";

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值