展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestPaixu {
public static void main(String[] args) throws NumberFormatException,
IOException {
System.out.println("请输入一个五位数");
BufferedReader strin = new BufferedReader(new InputStreamReader(
System.in));
String numStr = strin.readLine();
int[] numArray = new int[5];
for (int i = 0; i < 5; i++) {
numArray[i] = Integer.parseInt(numStr.substring(i, i + 1));
}
sort(numArray);
}
public static void sort(int[] numArray) {
for (int j = 1; j < numArray.length; j++) {
for (int i = 0; i < numArray.length - 1; i++) {
if (numArray[i] < numArray[i + 1]) {
int temp = numArray[i];
numArray[i] = numArray[i + 1];
numArray[i + 1] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
System.out.print(numArray[i]);
System.out.print(" ");
}
System.out.println();
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class TestPaixu {
public static void main(String[] args) throws NumberFormatException,
IOException {
System.out.println("请输入一个五位数");
BufferedReader strin = new BufferedReader(new InputStreamReader(
System.in));
String numStr = strin.readLine();
int[] numArray = new int[5];
for (int i = 0; i < 5; i++) {
numArray[i] = Integer.parseInt(numStr.substring(i, i + 1));
}
sort(numArray);
}
public static void sort(int[] numArray) {
for (int j = 1; j < numArray.length; j++) {
for (int i = 0; i < numArray.length - 1; i++) {
if (numArray[i] < numArray[i + 1]) {
int temp = numArray[i];
numArray[i] = numArray[i + 1];
numArray[i + 1] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
System.out.print(numArray[i]);
System.out.print(" ");
}
System.out.println();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class test3 {
public static void main(String[] args) {
int i = 12345;
System.out.println(getRevergeNumber(i));;
}
private static int getRevergeNumber(int k) {
// TODO Auto-generated method stub
int j;
char[] str = String.valueOf(k).toCharArray();
StringBuffer b = new StringBuffer();
for (int i = 0; i <str.length; i++) {
b.append(str[str.length-i-1]);
}
j = Integer.parseInt(b.toString());
return j;
}
}
验证过可以的
public static void main(String[] args) {
int i = 12345;
System.out.println(getRevergeNumber(i));;
}
private static int getRevergeNumber(int k) {
// TODO Auto-generated method stub
int j;
char[] str = String.valueOf(k).toCharArray();
StringBuffer b = new StringBuffer();
for (int i = 0; i <str.length; i++) {
b.append(str[str.length-i-1]);
}
j = Integer.parseInt(b.toString());
return j;
}
}
验证过可以的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package web;
public class Number {
public static void main(String[] args) {
String s = "12345";
StringBuffer sb = new StringBuffer();
for(int i=s.length()-1;i>-1;i--){
char c = s.charAt(i);
sb.append(String.valueOf(c)+" ");
}
System.out.println("逆序分离:"+sb);
}
}
结果:逆序分离:5 4 3 2 1
public class Number {
public static void main(String[] args) {
String s = "12345";
StringBuffer sb = new StringBuffer();
for(int i=s.length()-1;i>-1;i--){
char c = s.charAt(i);
sb.append(String.valueOf(c)+" ");
}
System.out.println("逆序分离:"+sb);
}
}
结果:逆序分离:5 4 3 2 1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询