java例子

来源:互联网 发布:linux 存储系统 编辑:程序博客网 时间:2024/06/03 12:11

public class mp {
 public static void main (String args[])  //1
 {
  int temp;
  int a[]={2,5,45,215,0,8,7,5,8,10};
  for(int i=0;i<a.length-1;i++)
  {
   for(int j=i+1;j<a.length;j++)
    if(a[i]>a[j])
    {
     temp=a[i];
     a[i]=a[j];
     a[j]=temp;     
    }
  }
  for(int k=0;k<a.length;k++)
   System.out.printf("  %d",a[k]); 
  }
}

lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

public class maopao {
 public static void main (String args[])  //1
 {
  int temp;
  int a[]={2,5,8,3,0,8,7,5,8,10};
  for(int i=1;i<a.length;i++)
  {
   for(int j=0;j<a.length-1-i;j++)
    if(a[j]>a[j+1])
    {
     temp=a[j];
     a[j]=a[j+1];
     a[j+1]=temp;     
    }
  }
  for(int k=0;k<a.length;k++)
   System.out.printf("  %d",a[k]);  
 }
}
llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

class circle
{
 static double PI=3.1415926;
 int rediums;
 public double areas()        //circle 类
 {
  return PI*rediums*rediums;  
 } 
 public void enlarge(int k)
    {
         rediums=rediums+k;
    }
}
class rectangle     //rectangle 类
{
 int width,length;
 public double areas()
 {
  return width*length;
 }
}
public class shape {
 public static void main(String args[])
 {
   
 circle c=new circle();
 //circle c1=new circle();
 rectangle r1=new rectangle();
 rectangle r2=new rectangle();
 c.rediums=10;
 
 r1.width=15;
 r1.length=20;
 r2.width=14;
 r2.length=21;
 double s1=c.areas();
 c.enlarge(10);
 double s2=r1.areas();
 double s3=r2.areas();
 double s4=c.areas();
 System.out.println("s1 has areas : "+s1); //第一个S大写;println;括号内无逗号
 System.out.println("s2 has areas : "+s2);
 System.out.println("s3 has areas : "+s3);
 System.out.println("s4 has areas : "+s4);
 }
}

0 0
原创粉丝点击