目录
Java?SE文章参考:Java SE入门及基础知识合集-CSDN博客
public class Student {????????public String name ;????????public int age ;????????public Student ( String name , int age ){????????????????this . name = name ;????????????????this . age = age ;????????}}
public class StudentTest {????????public static void main ( String [] args ) {????????????????int [] numbers = new int [ 2 ];????????????????numbers [ 0 ] = 10 ;????????????????Student [] students = new Student [ 2 ];????????????????students [ 0 ] = new Student ( " 张三 " , 20 );????????????????students [ 1 ] = new Student ( " 李四 " , 25 );????????}}
public class Course {????????public String number ; // 课程编号????????public String name ; // 课程名称????????public double score ; // 学分????????public Course ( String number , String name , double score ){????????????????this . number = number ;????????????????this . name = name ;????????????????this . score = score ;????????}}public class CourseTest {????????public static void main ( String [] args ) {????????????????Course [] courses = new Course [ 5 ];????????????????courses [ 0 ] = new Course ( "C0001" , "Java" , 5 );????????????????courses [ 1 ] = new Course ( "C0002" , "JDBC" , 2 );????????????????courses [ 2 ] = new Course ( "C0003" , "Html" , 3 );????????????????courses [ 3 ] = new Course ( "C0004" , "Jsp" , 6 );????????????????courses [ 4 ] = new Course ( "C0005" , "Spring" , 10 );????????}}
public class Mobile {????????public String brand ;????????public String type ;????????public double price ;????????public Mobile ( String brand , String type , double price ){????????????????this . brand = brand ;????????????????this . type = type ;????????????????this . price = price ;????????}}public class Seller {????????//数组中的默认值都是 null????????public Mobile [] mobiles = new Mobile [ 100 ];/*** 引用数据类型作为方法的参数* @param mobile*/????????public void playMobile ( Mobile mobile ){????????????????for ( int i = 0 ; i < mobiles . length ; i ++ ){????????????????????????if ( mobiles [ i ] == null ){????????????????????????????????mobiles [ i ] = mobile ;????????????????????????????????break ;????????????????????????}????????????????}????????}}public class SellerTest {????????public static void main ( String [] args ) {????????????????Seller seller = new Seller ();????????????????//调用售货员放手机????????????????seller . playMobile ( new Mobile ( " 小米 " , " 小米 10" , 2000 ));????????}}
public class ArraySort {????????public static void main ( String [] args ) {????????????????int [] arr1 = { 80 , 72 , 85 , 67 , 50 , 76 , 95 , 49 };????????????????int [] arr2 = { 77 , 90 , 92 , 89 , 67 , 94 };????????????????int [] arr3 = { 99 , 87 , 95 , 93 , 88 , 78 , 85 };????????????????sortDesc ( arr1 );????????????????System . out . println ( Arrays . toString ( arr1 ));????????????????sortDesc ( arr2 );????????????????System . out . println ( Arrays . toString ( arr2 ));????????????????sortDesc ( arr3 );????????????????System . out . println ( Arrays . toString ( arr3 ));}public static void sortDesc ( int [] arr ){????????//可以使用冒泡排序来对数组中的元素进行降序排列????????for ( int i = 0 ; i < arr . length ; i ++ ){????????????????for ( int j = 0 ; j < arr . length - i - 1 ; j ++ ){????????????????????????if ( arr [ j ] < arr [ j + 1 ]){????????????????????????????????int temp = arr [ j ];????????????????????????????????arr [ j ] = arr [ j + 1 ];????????????????????????????????arr [ j + 1 ] = temp ;????????????????????????}????????????????}????????}}}