Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - JAVA program problem
JAVA program problem
I changed it for you. I hope everyone will know about it before using it.

Then you can catch it when you transform. Then deal with it.

Import java.io.bufferedreader;

Import java.io.inputstreamreader;

/**

* Class Description: enter a string of numbers in this class.

* Numbers will be entered in descending order and printed.

*/

Public taxis {

/*

*blankNum records the number of spaces.

*intNums[] records the value of a string segment with an array.

*input records the input string.

*/

int int nums[];

String[] is empty;

String input;

/**

* function: getInputString ()

* Function: record the input string.

*/

public void getInputString() {

System.out.println ("Please enter a sort plastic number: enter format number+space+number");

Try {

buffered reader buffered reader = new buffered reader(new InputStreamReader(

system . in));

input = buffered reader . readline();

}catch (exception e) {

}

}

/**

* function: filterSpace ()

* Function: filter out the spaces before and after the string and those with more than two spaces in the middle to be calculated.

*/

public void filterSpace() {

/*

* Delete spaces at both ends of the string.

*trim () function removes spaces at the beginning and end of the string.

* Use format: str = str.trim ()

*/

input = input.trim()。

/*

* Read the string in turn, and intercept the string when two or more spaces are found.

* Enter input+space+intercepted string after the intercepted string.

*/

for(int I = 0; I & ltinput.length (). i++) {

if(input . charat(I)= " & amp; & ampinput . charat(I+ 1)= ' '){

input = input.substring(0,I)+" "+input . substring(I+ 1,input . length());

I-;

}

}

}

/**

* Function: setArray ()

* function: separate strings with spaces and convert the segmented contents into numeric types.

*/

public boolean setArray() {

/*

* Divide the string into segments with spaces, and record the contents of each segment in an array string of text type.

*/

string[]string = input . split(" ");

/*

* Convert the text array type to an integer.

*/

Boolean flag = true;

int nums = new int[string . length];

for(int I = 0; I< string. Length; i++){

Try {

int nums[I]= integer . parse int(string[I]);

} catch (Exception ex) {

System.out.println ("input error, please re-enter:");

flag = false

}

}

Return flag;

}

/**

* function: sortedIntDes ()

* Function: Compare sizes and sort from small to large.

*/

public void sortedIntDes() {

for(int I = 0; I & ltintNums.lengthi++){

for(int j = I+ 1; j & ltintNums.lengthj++){

if(intNums[I]& gt; intNums[j]){

int intTemp

int temp = int nums[j];

int nums[j]= int nums[I];

int nums[I]= int temp;

}

}

}

}

/**

* function: printArray ()

* print out the arranged numbers.

*/

public void printArray() {

for(int I = 0; I & ltintNums.lengthi++){

System.out.println ("Numbers from small to large:"+int nums [i]+"");

}

}

public static void main(String[]arge){

Taxi taxi = new taxi ();

for(; ; ){

taxis . getinputstring();

taxis . filter space();

if(taxis.setArray()){

taxis . sortedintdes();

taxis . print array();

}

}

}

}