/*
* TestInput.java
*
* Created on 2006年11月24日, 下午5:30
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author lbf
*/
import java.io.*;
import java.util.*;
public class TestInput {
//this Vector contains the input Integers
private Vector<Integer> v;
/** Creates a new instance of TestInput */
public TestInput() {
initOther();
readInput();
}
/*
*init the Vector
*/
private void initOther(){
v=new Vector<Integer>();
}
/*
*read the input number and do other
*/
private void readInput(){
try{
System.out.println("Please input number and press Enter,-1 for end!");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String input=null;
while((input=br.readLine())!=null){
int i=Integer.parseInt(input);
if(i!=-1){
v.add(i);
}else{
break;
}
}
Collections.sort(v);
System.out.println("The new sort numbers are:");
int sum=0;
for(int out:v){
sum+=out;
System.out.print(out+"\t");
}
System.out.println();
System.out.print("The average is:");
double ave=sum*1.0/v.size();
System.out.println(ave);
}
catch(Exception exe){
exe.printStackTrace();
}
}
public static void main(String[] args) {
new TestInput();
}
}
/*
* TestInput.java
*
* Created on 2006年11月24日, 下午5:30
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author lbf
*/
import java.io.*;
import java.util.*;
public class TestInput {
//this Vector contains the input Integers
private Vector<Integer> v;
/** Creates a new instance of TestInput */
public TestInput() {
initOther();
readInput();
}
/*
*init the Vector
*/
private void initOther(){
v=new Vector<Integer>();
}
/*
*read the input number and do other
*/
private void readInput(){
try{
System.out.println("Please input number and press Enter,-1 for end!");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String input=null;
while((input=br.readLine())!=null){
int i=Integer.parseInt(input);
if(i!=-1){
v.add(i);
}else{
break;
}
}
Collections.sort(v);
System.out.println("The new sort numbers are:");
int sum=0;
for(int out:v){
sum+=out;
System.out.print(out+"\t");
}
System.out.println();
System.out.print("The average is:");
double ave=sum*1.0/v.size();
System.out.println(ave);
}
catch(Exception exe){
exe.printStackTrace();
}
}
public static void main(String[] args) {
new TestInput();
}
}
受累受累,太敬业了