Java常用函数思想

 

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);

 


*/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值