我正在制作一个程序作为我在 java 中学习的培训,它可以查看用户输入的任何数字之间的偶数和奇数,如果我在开始时输入偶数,它会显示消息的问题
你没有输入偶数
如果用户在开始时输入了一个奇数,我只是希望他首先查看此消息
public static void main(String[] args) {
isevennumber(1, 5);
}
public static void isevennumber(int startwith, int endwith) {
for (int i = startwith; i <= endwith; i++) {
if (i % 2 == 0) {
System.out.println("you have entered an even number which is " + i);
} else {
System.out.println("you haven't entered an even number");
}
}
}
输出是
you haven't entered an even number
you have entered an even number which is 2
you haven't entered an even number
you have entered an even number which is 4
you haven't entered an even number
抱歉有任何错误,这是我在这里的第一篇文章
四季花海
隔江千里
BIG阳
相关分类