zoukankan      html  css  js  c++  java
  • 类与对象.

    package com.demo;

          public class Student {  

              String name;  

              char sex;   

              int age;  

    }

    package com.demo;

          public class StudentTest {

              public static void main(String[] args) {  

                 Student wangstu=new Student();   

                 wangstu.name="王洪涛";   
                 wangstu.age=18;  

                 wangstu.sex='女';  

                 wangstu.showStudent();   

        }

    }

    package com.demo;

         import java.util.Scanner;

            public class PersonTest {  

               public static void main(String[] args) {   

                  Person person=new Person();        

                  person.show();  

         }

    }

    protected:受保护的
      private:私有的
      public:公共的
      访问级别

    package com.demo;

         import java.util.Scanner;

           public class Person {

              public String name;

              public int age;    

               /**  

               * 用来循环接收用户输入,然后判断年龄  

               */    

               /**  

              * 如果类和属性还有方法不添加访问修饰符,那么默认是?  

              * 默认是public  

              */  

              public void show(){  

                         Scanner input=new Scanner(System.in);     

                         System.out.println("请输入姓名:");  

                         name=input.next();        

                         //1.循环   

                        while(!name.equals("n")){  

                                   System.out.println("请输入年龄:");  

                                    age=input.nextInt();  

                         //2.判断   

                         if(age>=18&&age<=60){    

                                   System.out.println("门票20元");  

                           }else{     

                                   System.out.println("门票免费");   

                           }   

                            System.out.println("请输入姓名:");   

                           name=input.next();    

                           }  

                            System.out.println("程序结束!");

          }

      }

  • 相关阅读:
    2017 Multi-University Training Contest
    ACM 竞赛高校联盟 练习赛 第一场
    hdu 6194 string string string(后缀数组)
    Codeforces Round #433 (Div. 1) D. Michael and Charging Stations(dp)
    Codeforces Round #433 (Div. 2) E. Boredom(主席树)
    Codeforces Round #433 (Div. 2) C. Planning(贪心)
    Codeforces Round #433(Div. 2) D. Jury Meeting(贪心)
    hdu 6191 Query on A Tree(dfs序+可持久化字典树)
    hdu 6183 Color it(线段树)
    poj 2464 Brownie Points II(扫描线)
  • 原文地址:https://www.cnblogs.com/wws553/p/9775796.html
Copyright © 2011-2022 走看看