public class Main{
public static void main(String args[]){
System.out.println("打印偶数:");
for( int i = 1; i <=100; i++){
if(i%2==0){
System.out.print(i+" ");
}
}
System.out.println();
System.out.println("打印奇数:");
for(int i = 1; i<=100; i++ ){
if(i%2==1){
System.out.print(i+" ");
}
}
}
}
利用求摸运算符就可以
public class MyTest{
public static void main(String[] args){
for(int i=0;i<100;i++){
if(i%2==0)
System.out.println(i+"是偶数");
else
System.out.println(i+"是奇数");
}
}
public class jiajia {
public static void main(String[] args) {
int i;
for(i=1;i<=100;i++)
{
if(i%2==0){
System.out.println(i+"是偶数");
}else{
System.out.println(i+"是奇数");
}
}
}
}
public
class
Main{
public
static
void
main(String
args[]){
System.out.println("打印偶数:");
for(
int
i
=
1;
i
<=100;
i++){
if(i%2==0){
System.out.print(i+"
");
}
}
System.out.println();
System.out.println("打印奇数:");
for(int
i
=
1;
i<=100;
i++
){
if(i%2==1){
System.out.print(i+"
");
}
}
}
}
利用求摸运算符就可以
public static void main(String[] args){
for(int i=0;i<100;i++,System.out.println(i+(i%2==0?":偶数":":奇数")));
}
//一行搞定