码迷,mamicode.com
首页 > 其他好文 > 详细

this关键字

时间:2018-01-30 17:00:33      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:pre   color   pow   span   scanner   gpo   字符串   ring   can   

this:关键字,是当前对象
    1.那个对象调用的,this就具备有那个身份
    2.this可以调用本类中的属性和方法
    3.this可以调用构造方法(本类)
        3.1.this不能调用当前自己的构造方法,会造成死循环
        3.2.this调用构造方法语句必须放在构造方法的首行
        3.3.this构造方法不能形成 闭环

calss Person{
  private String name;
  private int age;

  public Person(String name,int age){
     this.name =  name;            //这是1
     this.age = age;   
}

public Person(){
   // this();         //3.1
   this("aaa",20);     //调用构造方法 ,根据参数来决定调用那个构造方法,
}







//讲一个数字的字符串 变成整形的数值

public calss Test{
    public static void main(String[] args){
          Scanner s = new Scanner(System.in);
           System.out.println("请输入一个数字字符串");
            String num = s.next();
            //利api直接强转  Integer.parseInt(num);

             int length = num.length();
             int sum = 0;
             for(int i=0; i < num.length; i++){
                      char ch = num.charAt(i);
                      int n = ch - 0;
                       sum = sum + n*(int)(Math.pow(10,length - 1));
                        length--;
             }
          System.out.println(sum);
    }

}

 

this关键字

标签:pre   color   pow   span   scanner   gpo   字符串   ring   can   

原文地址:https://www.cnblogs.com/1950137408lxj/p/8384402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!