class Day2Test
{
public static void main(String[] args)
{
// System.out.println("Hello World!");
// getSum(); 求和
// getCount(); 记数
// get99(); number为9的乘法表,重载后改名为getCFB(),并带了参数
// getCFB(); 乘法表
// System.out.println("a"+1);
// System.out.println('1'+0);
}
/*
累加思想。
*/
public static void getSum()
{
int sum = 0;
for(int x=1; x<=100; x++)
{
sum += x;
}
System.out.println("sumn="+sum);
}
/*
计数器思想。
*/
public static void getCount()
{
int count = 0;
for(int x=1; x<100; x++)
{
if(x%6==0)
count++;
}
System.out.println("count="+count);
}
/*
大圈套小圈
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
*/
public static void getCFB() //重载下面的方法
{
getCFB(9);
}
/*
同样是乘法表,但是用户不想算到9,因为需求是让用户来指定。
*/
public static void getCFB(int num)
{
for(int x=1; x<=num; x++)
{
for(int y=1; y<=x; y++)
{
System.out.print(y+"*"+x+"="+y*x+"\t");
}
System.out.println();
}
}
/*
定义功能,根据传入的分数,确定等级。
90~100 ‘A' 80~89 'B' 70~79 ‘C' 60~69 ‘D' 'E'
*/
public static char getLevel(int num)
{
char ch ;
if(num>=90 && num<=100)
ch = 'a';
else if(num>=80 && num<=89)
ch = 'b';
else if(num>=70 && num<=79)
ch = 'c';
else if(num>=60 && num<=69)
ch = 'd';
else
ch = 'e';
return ch;
/*
if(num>=90 && num<=100)
return 'a';
else if(num>=80 && num<=89)
return 'b';
else if(num>=70 && num<=79)
return 'c';
else if(num>=60 && num<=69)
return 'd';
else
return 'e';
*/
}
}
/*
作业:
1,定义功能,根据传入的分数,确定等级。
90~100 ‘A' 80~89 'B' 70~79 ‘C' 60~69 ‘D' 'E'
2,
void show(int x,float y,char z)
{}
a,
void show(int z,float x,char y){} //没重载,因为这两个函数是一样的。
b,
void show(char z,float y,int x){} //重载。参数类型不一样。
c,
int show(int x,float y,char z){reutrn 1;} //没有,而且这个函数不可以和给定函数出现在同一个类中。
d,
void show(int x,char z) //重载了。个数不同。
{}
e,
void show(int a,float b,char c) //没重载,和给定函数一致。
{}
问:哪个答案和给定的函数重载了?
boolean b = true;
if(b=false)//if(b=false)
System.out.println("a");
else if(!b)
System.out.println("b");
else if(b)
System.out.println("c");
else
System.out.println("d");
int x=1,y=1;
if(x++==2 && ++y==2)
{
x = 5;
}
System.out.println("x="+x+",y="+y);
-----------------
int x=1,y=1;
if(x++==1 | ++y==2)
{
x = 5;
}
System.out.println("x="+x+",y="+y);
*/