----------------------android培训、java培训、期待与您交流! ----------------------
解答:Exchange.java
import java.util.Scanner;
class Exchange
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个整数");
String str = scanner.next();
System.out.println("你所输入的整数为"+str);
String stri;
//System.out.println(str.length()/2);
if((str.length()%2)==0)
stri = str;
else
stri = "0"+str;
char[] ch = stri.toCharArray();
for(int i=0;i<ch.length/2;i++)
{
int a = 2*i;
int b = 2*i+1;
swap(ch,a,b);
}
StringBuffer sb = new StringBuffer();
for(int i = 0; i < ch.length; i++){
sb.append(ch[i]);
}
String newStr = sb.toString();
System.out.println("第i位和第i+1位调换后的整数位为:"+newStr);
}
public static void swap(char[] ch,int x,int y)
{
char temp = ch[x];
ch[x]=ch[y];
ch[y]=temp;
}
}
---------------------- android培训、java培训、期待与您交流! ----------------------
详细请查看:http://edu.csdn.net/heima