课堂作业
文章平均质量分 56
小肥鸡正在学习
这个作者很懒,什么都没留下…
展开
-
set方法和构造函数
public class TestDemo { public static void main(String[] args) { Test t=new Test(-1); System.out.println(t.getAge());//-1,setAge()内的条件对构造函数初始化无影响,因为new一个对象后紧跟着执行构造函数 ...原创 2018-07-18 19:29:08 · 1695 阅读 · 0 评论 -
Instanceof
public class InstanceofTest { public static void main(String[] args) { Person p=new Chinese(); System.out.println(p instanceof Person);//true System.out.println(p insta...原创 2018-07-30 12:09:01 · 109 阅读 · 0 评论 -
生成API文档
/** 定义一个工具类,可以对数组进行寻找最大最小值和排序运算。 @author 小庞 @version 1.1 */ public class ArrayTools { /** 获取数组里最大值的方法 @param arr 传入一个整型数组 @return 返回一个int类型的数 */ public static int getMax(int[] ...原创 2018-07-20 20:29:42 · 114 阅读 · 0 评论 -
Static的注意事项与应用
public class StaticDemo { public static void main(String[] args) { Person p=new Person("狗剩"); p.show(); } } class Person { String name; //每一个对象都有国籍,如果定义为实例变量的话每个对...原创 2018-07-20 09:56:23 · 122 阅读 · 0 评论 -
this关键字在构造函数间的调用
public class ThisDemoTwo { public static void main(String[] args) { System.out.println("Hello World!"); } } //构造函数间的调用要使用关键字this(无参,参数1,参数2...) class Person { private int age;...原创 2018-07-20 09:10:47 · 1181 阅读 · 0 评论 -
this应用
public class ThisDemo { public static void main(String[] args) { Person p=new Person(20); Person p1=new Person(20); boolean b=p.compare(p1); System.out.println(...原创 2018-07-19 20:34:10 · 167 阅读 · 0 评论 -
选择排序
public class TestTwo{ public static void main(String[] args) { //2.对11个数(10到100以内)进行排序(要求使用选择排序算法) //原理:每次循环从数组中选择出一个最小或者最大的元素,按顺序重新放入数组中,直到所有的排序元素都排序完成 int[] a={77,54,91,3...原创 2018-07-13 16:11:48 · 96 阅读 · 0 评论 -
构造函数与构造代码块
public class TestDemo { public static void main(String[] args) { Person p1=new Person(0); System.out.println(p1.getAge()+"岁"); Person p2=new Person(1); System.o...原创 2018-07-19 10:49:51 · 135 阅读 · 0 评论 -
输入三角形行数,打印空心三角形
import java.util.Scanner;public class AngleOne { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入三角形的行数:"); int line=sc.n...原创 2018-07-12 19:55:59 · 1568 阅读 · 0 评论 -
打印等腰三角形
/*----*---* *--* * *-* * * ** * * * **//*class Day03111{ public static void main (String[] args) { //控制行数 for(int x=0;x<5;x++) { //打印“—” for(int y=x...原创 2018-07-13 11:27:02 · 161 阅读 · 0 评论 -
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
import java.util.Scanner;public class TestOne { public static void main(String[] args) { /* 1. 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 */ Scanner sc=new Scanner(System.i...原创 2018-07-13 10:11:53 · 6040 阅读 · 0 评论 -
对数组进行排序
public class PaiXu { public static void main(String[] args) { //初始化一个数组 int[] a={5,6,9,8,2,1,4}; //取a[i] for(int i=0;i<a.length-1;i++) { //每次由一...原创 2018-07-12 20:06:10 · 239 阅读 · 0 评论 -
多态中成员的特点
public class DuoTaiDemo1 { public static void main(String[] args) { /*多态中静态成员函数的特点:无论编译还是运行,都参考左边引用型变量所属的类 Fu f=new Zi(); f.method4();//fu method_4,只要类一加载,静态函数就存在了,而且静态...原创 2018-07-28 13:43:54 · 275 阅读 · 0 评论