单循环比赛程序
有偶數(shù)支足球隊(duì)進(jìn)行單循環(huán)比賽,請(qǐng)按照指定算法打印每輪的對(duì)陣形勢(shì)
public class ArrayDemo3 {
public static void main(String[] args) {
planGame();
}
public static void planGame(){
String[] teams=new String[]{"T1","T2","T3","T4"};
for (int i = 1; i < teams.length; i++) {
System.out.println();
System.out.println("這是第"+i+"輪比賽");
for (int j = 0; j < teams.length/2; j++) {
System.out.println(teams[j]+" VS "+teams[teams.length-1-j]);
}
String temp = teams[teams.length - 1];
for(int k = teams.length-1;k > 1;k--){
teams[k] = teams[k - 1];
}
teams[1] = temp;
}
}
}
public class ArrayDemo3 {
public static void main(String[] args) {
planGame();
}
public static void planGame(){
String[] teams=new String[]{"T1","T2","T3","T4"};
for (int i = 1; i < teams.length; i++) {
System.out.println();
System.out.println("這是第"+i+"輪比賽");
for (int j = 0; j < teams.length/2; j++) {
System.out.println(teams[j]+" VS "+teams[teams.length-1-j]);
}
String temp = teams[teams.length - 1];
for(int k = teams.length-1;k > 1;k--){
teams[k] = teams[k - 1];
}
teams[1] = temp;
}
}
}
總結(jié)
- 上一篇: 现在需要在input框输入年月yyyym
- 下一篇: 一键实现前程无忧(51job)简历不停刷