进度报告4

(1)代码案例练习
1.

public class helloworld {
public static void main(String[] args) {
double Price;int month;String x;
Price=price(1000,6,"头等舱") ;
System.out.println("优惠价为:"+Price);
}
public static double price(double a,int b,String c){
if(b>=5&&b<=10)
{
switch(c){
case "头等舱":a=0.9;break;
case "经济舱":a
=0.85;break;
}
return a;
}
else
{
switch(c){
case "头等舱":a=0.7;break;
case "经济舱":a
=0.65;break;
}
return a;
}
}
}

2.

public class helloworld {
public static void main(String[] args) {
String code="";
yzm(4,"");
}
public static void yzm(int N,String code){
Random r=new Random();
for(int i=1;i<=N;i++){
int x= r.nextInt(3);
switch (x){
case 0:int a=r.nextInt(10);code+=a;break;
case 1:char ch1=(char)(r.nextInt(26)+65);code+=ch1;break;
case 2:char ch2=(char)(r.nextInt(26)+97);code+=ch2;break;
}
}
System.out.println(code);
}
}

3.

public class helloworld {
public static void main(String[] args) {
int[] score = new int[10];
for (int i = 0; i < 10; i++) {
Scanner sc = new Scanner(System.in);
int b = sc.nextInt();
score[i] = b;
}
findmax(score);findmin(score);
double sum=0;
for(int i=0;i<10;i++){
sum+=score[i];
}
double aver=sum/8;
System.out.println("平均分为:"+aver);
}

public static void findmax(int a[]) {
    int max = a[0];
    int j = 0;
    for (int i = 0; i < 10; i++) {
        if (max < a[i]) {
            max = a[i];
            j = i;
        }
    }
    a[j] = 0;
}

public static void findmin(int a[]) {
    int min = a[0];
    int j = 0;
    for (int i = 0; i < 10; i++) {
        if (min > a[i]) {
            min = a[i];
            j = i;
        }
    }
    a[j] = 0;
}

}

4.

public class helloworld {
public static void main(String[] args) {
int[] secret=new int[]{1,9,8,3};
for(int i=0;i<4;i++){
secret[i]=(secret[i]+5)%10;
}
for(int i=0;i<4;i++){
int temp=0;
temp=secret[i];
secret[i]=secret[3-i];
secret[3-i]=temp;
}
String a="";
for(int i=0;i<4;i++){
a+=secret[i];
}
System.out.println(a);
}
}

(2)明天继续练习案例习题

posted @ 2024-07-10 18:06  茆伟昊  阅读(8)  评论(0编辑  收藏  举报