Eclipse运行带参数的java程序


Java代码 复制代码  收藏代码
  1. public class testIntArray {  
  2.   
  3.     /** 
  4.      * @带参数的Java程序运行 
  5.      */  
  6.     public static void main(String[] args) {  
  7.         // 参数存储在args数组中  
  8.         int [] anArray = new int [10];  
  9.         for (int i=0;i<10;i++){  
  10.             anArray[i] = Integer.parseInt(args[i]);  
  11.         }  
  12.         SortIt(anArray);  
  13.     }  
  14.   
  15.     public static  void SortIt(int [] a){  
  16.         for(int i=0;i<a.length;i++){  
  17.             for(int j=0;j<i;j++){  
  18.                 if(a[j]>a[j+1]){  
  19.                     int temp;  
  20.                     temp=a[j+1];  
  21.                     a[j+1]=a[j];  
  22.                     a[j]=temp;  
  23.                 }  
  24.             }  
  25.         }  
  26.         for(int i=0;i<a.length;i++){  
  27.             System.out.print(a[i]+" ");  
  28.         }  
  29.     }  
  30. }  
public class testIntArray {

	/**
	 * @带参数的Java程序运行
	 */
	public static void main(String[] args) {
		// 参数存储在args数组中
		int [] anArray = new int [10];
		for (int i=0;i<10;i++){
			anArray[i] = Integer.parseInt(args[i]);
		}
		SortIt(anArray);
	}

	public static  void SortIt(int [] a){
		for(int i=0;i<a.length;i++){
			for(int j=0;j<i;j++){
				if(a[j]>a[j+1]){
					int temp;
					temp=a[j+1];
					a[j+1]=a[j];
					a[j]=temp;
				}
			}
		}
		for(int i=0;i<a.length;i++){
			System.out.print(a[i]+" ");
		}
	}
}



运行的方法是,右键——》run as——》run configuration——》Arguments——》program arguments    输入 6 2 1 4 5 6 9 8 9 10
即 每一个参数用空格分开。

运行结果:
1 2 4 5 6 6 8 9 9 10
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值