第九章代码

原创 2013年12月03日 18:36:33
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");
}


}


}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

《C++编程思想》 第九章 命 名 控 制 (原书代码+知识点+习题+解答)

一.相关知识点         那些通常放在头文件里的名字,像常量、内联函数(inline function),在缺省情况下都是内部连接的(当然常量只有在C + +中缺省情况下是内部连接的,在 C中它...

数据名称 (代码大全 第九章 )

9.1 选择名称 9.1.1 命名时要考虑的最重要问题 在给变量命名时,考虑的问题是变量名称是否完全而又准确地描述了变量所代表的实体。 9.1.2 面向问题 一个好记的名字通常是面向问...

asp.net第九章代码

  • 2009-01-07 10:48
  • 18KB
  • 下载

代码整洁之道精华——第九章 单元测试

阅读本文有两种原因:第一,你是个程序员;第二,你想成为更好的程序员。你如果想成为更好的程序员,那就请细细品味文章内容,它绝不会让你失望。
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)