java数组循环问题
答案:1 悬赏:70
解决时间 2021-02-12 08:17
- 提问者网友:放荡不羁
- 2021-02-12 04:19
java数组循环问题
最佳答案
- 二级知识专家网友:心痛成瘾
- 2021-02-12 05:04
package cn.test;
import java.util.Scanner;
public class Test {
static int count=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String s=sc.next();
char[] c=s.toCharArray();
s(c,c.length,c.length);
}
public static void s(char[] c,int length,int count){
if(count==0){
System.exit(0);
}else{
char temp;
for(int i=0;i<length;i++){
temp=c[i];
if(i==length-1){
c[i]=temp;
}else{
c[i]=c[i+1];
c[i+1]=temp;
}
System.out.print(c[i]);
}
System.out.println();
count=count-1;
}
s(c,length,count);
}
}
这是我写的,已经试验过了的,效果跟你要的一样
import java.util.Scanner;
public class Test {
static int count=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String s=sc.next();
char[] c=s.toCharArray();
s(c,c.length,c.length);
}
public static void s(char[] c,int length,int count){
if(count==0){
System.exit(0);
}else{
char temp;
for(int i=0;i<length;i++){
temp=c[i];
if(i==length-1){
c[i]=temp;
}else{
c[i]=c[i+1];
c[i+1]=temp;
}
System.out.print(c[i]);
}
System.out.println();
count=count-1;
}
s(c,length,count);
}
}
这是我写的,已经试验过了的,效果跟你要的一样
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |