java小程序Array
classArray{privateinttemp[]=null;privateintfoot=0;publicArray(intlen){if(len>0){this....
class Array{
private int temp[]=null;
private int foot = 0;
public Array(int len){
if(len>0){
this.temp=new int[len];
}
else{
this.temp=new int[1];
}
}
public boolean add(int i){
if(this.foot<this.temp.length){
this.temp[this.foot]=i;
this.foot++;
return true;
}
else{
return false;
}
}
public int[] getArray(){
return this.temp;
}
}
class SortArray extends Array{
public SortArray(int len){
super(len);
}
public int[] getArray(){
java.util.Arrays.sort(super.getArray());
return super.getArray();
}
}
class ReverseArray extends Array{
public ReverseArray(int len){
super(len);
}
public int[] getArray(){
int rt[] = new int[super.getArray().length];
int count = rt.length-1;
for(int x=0;x<rt.length;x++){
rt[count]=super.getArray()[x];
count--;
}
return rt;
}
}
class Demo17{
public static void main(String args[]){
ReverseArray arr = new ReverseArray(6);
arr.add(21);
arr.add(3);
arr.add(5);
arr.add(523);
arr.add(243);
arr.add(55);
System.out.println(arr.getArray()[2]);
}
/*
public static void print(int x[]){
for(int i=0;i<x.length;i++)
{
System.out.println(x[i]);
}
}*/
} 展开
private int temp[]=null;
private int foot = 0;
public Array(int len){
if(len>0){
this.temp=new int[len];
}
else{
this.temp=new int[1];
}
}
public boolean add(int i){
if(this.foot<this.temp.length){
this.temp[this.foot]=i;
this.foot++;
return true;
}
else{
return false;
}
}
public int[] getArray(){
return this.temp;
}
}
class SortArray extends Array{
public SortArray(int len){
super(len);
}
public int[] getArray(){
java.util.Arrays.sort(super.getArray());
return super.getArray();
}
}
class ReverseArray extends Array{
public ReverseArray(int len){
super(len);
}
public int[] getArray(){
int rt[] = new int[super.getArray().length];
int count = rt.length-1;
for(int x=0;x<rt.length;x++){
rt[count]=super.getArray()[x];
count--;
}
return rt;
}
}
class Demo17{
public static void main(String args[]){
ReverseArray arr = new ReverseArray(6);
arr.add(21);
arr.add(3);
arr.add(5);
arr.add(523);
arr.add(243);
arr.add(55);
System.out.println(arr.getArray()[2]);
}
/*
public static void print(int x[]){
for(int i=0;i<x.length;i++)
{
System.out.println(x[i]);
}
}*/
} 展开
展开全部
class Array{
private int temp[]=null; //5:
private int foot = 0; //6:
public Array(int len){ //4:初始化一个类,必先初始化属性
if(len>0){ //7:完成父类的初始化,回到子类ReverseArray
this.temp=new int[len];
}
else{
this.temp=new int[1];
}
}
public boolean add(int i){ //11:创建数组temp[6]
if(this.foot<this.temp.length){
this.temp[this.foot]=i;
this.foot++;
return true;
}
else{
return false;
}
}
public int[] getArray(){
return this.temp;
}
}
class SortArray extends Array{
public SortArray(int len){
super(len);
}
public int[] getArray(){
java.util.Arrays.sort(super.getArray());
return super.getArray();
}
}
class ReverseArray extends Array{
public ReverseArray(int len){ //3:初始化一个类,必先初始化父类
super(len); //8:调用父类构造方法,再回到子子类Demo17
}
public int[] getArray(){ //14:调用该方法
//15:调用父类getArray()方法,返回temp数组的值,new一个新数组rt[6]
int rt[] = new int[super.getArray().length];
int count = rt.length-1; //16:count=6-1=5
for(int x=0;x<rt.length;x++){ //17:将temp数组的值倒序排列给rt数组
rt[count]=super.getArray()[x];//rt[0]=55,rt[1]=243,rt[2]=523,
count--; //rt[3]=5,rt[4]=3,rt[5]=21
}
return rt;
}
}
class Demo17{
public static void main(String args[]){ //1:程序进入
//2:调用构造函数ReverseArray(int len);
//9:进行赋值,完成构造函数arr
ReverseArray arr = new ReverseArray(6);
arr.add(21); //10:调用父类add方法
arr.add(3);
arr.add(5);
arr.add(523);
arr.add(243);
arr.add(55); //12:调用结束,temp[0]=21,temp[1]=3,temp[2]=5,
//temp[3]=523,temp[4]=243,temp[5]=55,
//13:调用父类getArray()方法,得到rt[2]=523
System.out.println(arr.getArray()[2]);
}
/*
public static void print(int x[]){
for(int i=0;i<x.length;i++)
{
System.out.println(x[i]);
}
}*/
}
private int temp[]=null; //5:
private int foot = 0; //6:
public Array(int len){ //4:初始化一个类,必先初始化属性
if(len>0){ //7:完成父类的初始化,回到子类ReverseArray
this.temp=new int[len];
}
else{
this.temp=new int[1];
}
}
public boolean add(int i){ //11:创建数组temp[6]
if(this.foot<this.temp.length){
this.temp[this.foot]=i;
this.foot++;
return true;
}
else{
return false;
}
}
public int[] getArray(){
return this.temp;
}
}
class SortArray extends Array{
public SortArray(int len){
super(len);
}
public int[] getArray(){
java.util.Arrays.sort(super.getArray());
return super.getArray();
}
}
class ReverseArray extends Array{
public ReverseArray(int len){ //3:初始化一个类,必先初始化父类
super(len); //8:调用父类构造方法,再回到子子类Demo17
}
public int[] getArray(){ //14:调用该方法
//15:调用父类getArray()方法,返回temp数组的值,new一个新数组rt[6]
int rt[] = new int[super.getArray().length];
int count = rt.length-1; //16:count=6-1=5
for(int x=0;x<rt.length;x++){ //17:将temp数组的值倒序排列给rt数组
rt[count]=super.getArray()[x];//rt[0]=55,rt[1]=243,rt[2]=523,
count--; //rt[3]=5,rt[4]=3,rt[5]=21
}
return rt;
}
}
class Demo17{
public static void main(String args[]){ //1:程序进入
//2:调用构造函数ReverseArray(int len);
//9:进行赋值,完成构造函数arr
ReverseArray arr = new ReverseArray(6);
arr.add(21); //10:调用父类add方法
arr.add(3);
arr.add(5);
arr.add(523);
arr.add(243);
arr.add(55); //12:调用结束,temp[0]=21,temp[1]=3,temp[2]=5,
//temp[3]=523,temp[4]=243,temp[5]=55,
//13:调用父类getArray()方法,得到rt[2]=523
System.out.println(arr.getArray()[2]);
}
/*
public static void print(int x[]){
for(int i=0;i<x.length;i++)
{
System.out.println(x[i]);
}
}*/
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询