第九章代码

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值