关闭

第九章代码

257人阅读 评论(0) 收藏 举报
package Waljl1;


import java.util.Scanner;


public class Waljl01 {


public static void main(String[] args) {
String[] musics = new String[] { "Island", "Ocean", "pretty", "sun" };
String[] newMusics = new String[musics.length + 1];
String music = "";
int index = musics.length;
System.out.println("插入前的数组为:");
for (int i = 0; i < musics.length; i++) {
System.out.println(musics[i] + "");
}
for (int i = 0; i < musics.length; i++) {
newMusics[i] = musics[i];
}
Scanner input = new Scanner(System.in);
System.out.println("\n请输入歌曲名称");
music = input.nextLine();
for (int i = 0; i < musics.length; i++) {
if (musics[i].compareToIgnoreCase(music) > 0) {
index = i;
break;
}
}
for (int i = newMusics.length - 1; i > index; i--) {
newMusics[i] = newMusics[i - 1];
}
newMusics[index] = music;
System.out.println("插入后的数组为:");
for (int i = 0; i < newMusics.length; i++) {
System.out.println(newMusics[i] + " ");
}


}


}








package Waljl1;


import java.util.Scanner;


public class Waljl02 {


public static void main(String[] args) {
int[] score = new int[4];
int classNum = 3;
double sum = 0.0;
double[] average = new double[classNum];
Scanner input = new Scanner(System.in);
for (int i = 0; i < classNum; i++) {
sum = 0.0;
System.out.println("请出入第" + (i + 1) + "个班级的成绩");
for (int j = 0; j < score.length; j++) {
System.out.println("第" + (j + 1) + "个学员的成绩");
score[j] = input.nextInt();
sum = sum + score[j];
}
average[i] = sum / score.length;
System.out.println("第" + (i + 1) + "个班级参赛学员的平均分是:" + average[i]
+ "\n");


}


}


}







package Waljl1;


public class Waljl03 {


public static void main(String[] args) {
int rows=3;
System.out.println("打印直角三角形");
for (int i = 0; i < rows; i++) {
for (int j = 0; j <= i; j++) {
System.out.println("*");
}


}


}


}







package Waljl1;


import java.util.Scanner;


public class Waljl04 {


public static void main(String[] args) {
int rows = 0;
System.out.println("请输入直角三角形的行数");
Scanner input = new Scanner(System.in);
rows = input.nextInt();
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows + 1 - i; j++) {
System.out.println("*");
}


}


}


}






package Waljl1;


import java.util.Scanner;


public class Waljl05 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int rows = 0;
System.out.println("请输入菱形行数");
rows = input.nextInt();
while (rows % 2 == 0) {
System.out.println("请输入奇术");
rows = input.nextInt();
}
int n = (rows + 1) / 2;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.println(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.println("*");
}


}
}


}







package Waljl1;


import java.util.Scanner;


public class Waljl06 {


public static void main(String[] args) {
int[] score = new int[4];
int classNum = 3;
double sum = 0.0;
double[] average = new double[classNum];
int count = 0;
Scanner input = new Scanner(System.in);
for (int i = 0; i < classNum; i++) {
sum = 0.0;
System.out.println("请出入第" + (i + 1) + "个班级的成绩");
for (int j = 0; j < score.length; j++) {
System.out.println("第" + (j + 1) + "个学员的成绩");
score[j] = input.nextInt();
sum = sum + score[j];
if (score[j] < 85) {
continue;
}
count++;
}
average[i] = sum / score.length;
System.out.println("第" + (i + 1) + "个班级参赛学员的平均分是:" + average[i]
+ "\n");


}
System.out.println("成绩85分以上的学员人数有:" + count + "人");
}


}







package Waljl1;


import java.util.Scanner;


public class Waljl07 {


public static void main(String[] args) {
int count = 0;
String choice;
Scanner input = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
System.out.println("欢迎光临第" + (i + 1) + "家专卖店");
for (int j = 0; j < 3; j++) {
System.out.println("要离开吗(y/n)?");
choice = input.nextLine();
if ("y".equals(choice)) {
break;
}
System.out.println("买了一件衣服");
count++;
}
System.out.println("离店结账");
}
System.out.println("总共买了" + count + "件衣服");
choice = input.nextLine();
}


}








package Waljl1;


public class Waljl08 {


public static void main(String[] args) {
int rows = 9;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.println(j + "*" + i + "=" + j * i + "  ");
}
System.out.println("\n");
}


}


}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2854次
    • 积分:123
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:0篇
    • 译文:0篇
    • 评论:3条
    文章存档
    最新评论