2.写出输出结果。
class Demo
{
public static void main(String[] args)
{
show(0);
show(1);
}
public static void show(int i)
{
switch(i)
{
default:
i+=2;
case 1:
i+=1;
case 4:
i+=8;
case 2:
i+=4;
}
System.out.println("i="+i);
}
}
15
16
3.写出输出的结果.
class Demo
{
public static void main(String[] args)
{
int x=0,y=1;
if(++x==y-- & x++==1||--y==0)
System.out.println("x="+x+",y="+y);
else
System.out.println("y="+y+",x="+x);
}
}
x=2,y=0
4.求出1~100之间,即使3又是7的倍数出现的次数?
class Demo10
{
public static void main(String[] args)
{
int k = sum();
System.out.println(k);
}
public static int sum()
{
int counter=0;
for (int i = 1; i <= 100; i++)
{
if (i%3==0 && i%7==0)
{
counter++;
}
}
return counter;
}
}
5.用程序的方式显示出下列结果。
11=1
12=2 22=4
13=3 23=6 33=9
14=4 24=8 34=12 44=16
15=5 25=10 35=15 45=20 5*5=25
class Demo11
{
public static void main(String[] args)
{
for (int i=1; i<=5; i++)
{
for (int j=1; j<=i; j++)
{
System.out.print(j + "*" + i + "=" + j*i + "\t");
}
System.out.println();
}
}
}
6.写出程序结果。
class Demo
{
public static void main(String[] args)
{
int x = 1;
for(show('a'); show('b') && x<3; show('c'))
{
show('d');
x++;//3
}
}
public static boolean show(char ch)
{
System.out.println(ch);
return true;
}
}
a
b
d
c
b
d
c
b