The first Java programming of mine
来源:互联网 发布:单片机555脉冲发生器 编辑:程序博客网 时间:2024/05/24 01:40
/* * * Writer: Sunxin. * Date:2017.2.28. * Main:My first Java programming. * * 注:对以下程序操作时需要在src根目录下创建三个不同的类分别存放。 * * */// The class of Counterpublic class Counter {private int number;public Counter(){number = 100;}public Counter(int n){number = n;}public void add(){number += 1;}public int getNumber() {return number;}public void setNumber(int number) {this.number = number;}}// The class of Studentpublic class Student {private int number;private String name;//Constructorpublic Student(int number,String name){this.number = number;this.name = name;}public String toString(){return "name:"+name+" number:"+number;}public boolean equals(Object ss){boolean result = false;Student temp = (Student)ss;if(this.number == temp.getNumber()){result = true;}return result;}public int getNumber() {return number;}public void setNumber(int number) {this.number = number;}public String getName() {return name;}public void setName(String name) {this.name = name;}}import java.util.Scanner;import java.util.ArrayList;public class HelloJava {public static void main(String[] args){int n;Scanner scanner = new Scanner(System.in);Counter c = new Counter(300);//c.setNumber(17);c.add();c.add();Counter c2 = new Counter(); // the default constructorSystem.out.println("c = "+c.getNumber());System.out.println("c2 = "+c2.getNumber());// create some object of the class (Student)Student s = new Student(123,"Stark");Student s2;s2 = new Student(456,"Ariye");System.out.println("Hello "+s.toString());System.out.println("Hello "+s2.toString());Student s3 = new Student(123,"Stark"); ArrayList<Student> students;students = new ArrayList<Student>();students.add(s);students.add(s2);students.remove(s3); //find the same of id which will be removed.System.out.println(students.toString());// the cmp of the stringString a = new String("ABD");String b = new String("ABC");if(a.equals(b)){System.out.println("a is equals to b");}else{System.out.println("a is not equals to b");}//int[] s;//s = new int[10];//for(int i = 0; i<10; i++){//s[i] = i+1;//}//for(int i = 0; i<10; i++){//System.out.println(s[i]);//}}}
0 0
- The first Java programming of mine
- The First Blog of Mine
- the first log of mine
- The first blog of mine...
- The first step of Java[1]
- The first step of Java[2]
- The first step of Java[3]
- The first step of Java[4]
- The first step of Java[5]
- The first step of Java[6]
- The first step of Java[7]
- The first step of Java[8]
- The first step of Java[9]
- The first step of Java[10]
- The first step of Java[11]
- The first step of Java[12]
- The first day of learning java
- The first day of learn java
- 蓝桥杯 BASIC-3 基础练习 字母图形
- Runtime
- Oracle PL-SQL Developer集成TFS进行团队脚本文件版本管理
- mongodb-常用命令介绍
- 计算机视觉代码
- The first Java programming of mine
- fiddler本地文件替代服务器文件测试
- 前端在html页面之间传递参数的方法
- c++ primer 练习 2.15、2.16、2.17
- 蓝桥杯 BASIC-4 基础练习 数列特征
- 蓝桥杯 入门训练 Fibonacci数列问题
- Mac虚拟机里ios+Python+Appium环境搭建
- AndroidManifest.xml 安卓清单文件
- intellij idea 生成可执行jar 运行提示没有主清单属性