第二课写的几个小作业
//1000内水仙花个数
class ShuiXian{ public static void main(String[] args){ int a; int b; int c; for(int i = 100;i <1000; i++){ a = i/100; b = i%100/10; c = i%10; if((a*a*a+b*b*b+c*c*c)==i){ System.out.println(i+"是一个水仙花数"); } } } }
//回文数
class HuiWen{
public static void main(String[] args){
int a,b,c,d,e;
for(int i = 10000;i <99999; i++){
a = i/10000;
b = i%10000/1000;
c = i%1000/100;
d = i%100/10;
e = i%10;
if(a==(c-2)&&b==(c-1)&&d==b&&e==a){
System.out.println(i+"是一个回文数");
}
}
}
}
//99乘法表
class Multiplication{
public static void main(String[] args){
int a;
int b;
for(a = 1; a <= 9;a++){
for(b =1; b<=a; b++){
System.out.print(b+"*"+a+"="+a*b+" ");
}
System.out.println();
}
}
}
//评委打分
import java.util.Scanner;
public class Score {
public static void main(String[] args) {
int[] Sco = new int[8];
Scanner Mark = new Scanner(System.in);
for (int i = 0; i < Sco.length; i++) {
int a = i+1;
System.out.println("请输入第"+a+"评委的分数");
Sco[i] = Mark.nextInt();
}
//对数组进行排序,最大的数移动到第一个元素。最小的移动到最后元素
for (int i = 0; i < Sco.length; i++) {
int a = i+1;
if (a==Sco.length) {
break;
}
int b = Sco.length-1;
if (Sco[a]>Sco[0]) {
Sco[0]=Sco[0]+Sco[a];
Sco[a]=Sco[0]-Sco[a];
Sco[0]=Sco[0]-Sco[a];
}else if(Sco[b]>Sco[i]){
Sco[b]=Sco[b]+Sco[i];
Sco[i]=Sco[b]-Sco[i];
Sco[b]=Sco[b]-Sco[i];
}
}
//显示排序后的分数
PaiXu(Sco);
System.out.println();
//不知道数组的元素的删除方法。就用了笨一点的方法。
float m = 0;
for (int i = 1; i < Sco.length-1; i++) {
m = m + Sco[i];
}
String num =String.format("%.2f",(m/(Sco.length-2)));
System.out.println("去掉最高分和最低分后的平均分是=>"+num);
}
private static void PaiXu(int[] Sco) {
for (int i = 0; i < Sco.length; i++) {
System.out.print(" "+Sco[i]+" ");
}
}
}