java作业之实验一程序设计初步——温度转换

java作业之实验一程序设计初步——温度转换

1、由命令行输入一个成绩,使用条59件分支结构语句求出成绩的等级。

要求效果:A:90-100;B:80-89;C:70-79;D:60-69;E:0-59。

提示:推荐使用switch开关语句。

package shiyan1;
import java.util.Scanner;
public class shiyan1_1 {
	public static void main(String[] args) {
		Scanner stdin=new Scanner (System.in);
		while(true) {
		System.out.println("输入您的成绩:");
		int score=stdin.nextInt();
		int type;
		if(0<=score&&score<=59) {
			type=1;
		}
		else if(60<=score&&score<=69) {
			type=2;
		}
		else if(70<=score&&score<=79) {
			type=3;
		}
		else if(80<=score&&score<=89) {
			type=4;
		}
		else if(90<=score&&score<=100) {
			type=5;
		}
		else {
			type=0;
		}
		switch(type){
		case 5:System.out.println("您的等级为:A");break;
		case 4:System.out.println("您的等级为:B");break;
		case 3:System.out.println("您的等级为:C");break;
		case 2:System.out.println("您的等级为:D");break;
		case 1:System.out.println("您的等级为:E");break;
		default :System.out.println("您输入的成绩无效!");break;
		}
		}
	}
}

2、利用以下两种循环结构实现1~10阶乘之和。

for循环和while循环。

提示:可以通过声明多个变量实现,也可以考虑使用递归。

package shiyan1;
public class shiyan1_2 {
	public static void main(String[] args) {
		forSum(10);//for语句实现
		whielrSum(10);//while语句实现
	}
	public static int forSum(int num) {
		int sum=0;
		for(int i=num;i>1;i--) {
			int all=1;
			for(int j=i;j>1;j--) {
				all=all*j;
			}
			sum=sum+all;
		}
		System.out.println("结果:"+sum);
		return 0;
	}
	public static int whielrSum(int num) {
		int sum=0;
		while(num>=1) {
			int jiecheng=num;
			int all=1;
			while(jiecheng>=1) {
				all*=jiecheng;
				jiecheng--;
			}
			sum+=all;
			num--;
		}
		System.out.println("结果:"+sum);
		return 0;
	}
}

3、在屏幕上打印出n行的金字塔图案。

例如:若n=3,则图案如下:

        *

       ***

      *****

package shiyan1;
import java.util.Scanner;
public class shiyan1_3 {
	public static void main(String[] args) {
		Scanner stdin=new Scanner (System.in);
		System.out.println("输入n:");
		int n=stdin.nextInt();
		for(int i=1;i<=n;i++) {
			int m=i;
			int k=i;
			while(k<n) {
				System.out.print(" ");
				k++;
			}
			System.out.print("*");
			while(m>1) {
					System.out.print("*");
				m--;
			}
			m=i;
			while(m>1) {
				System.out.print("*");
			m--;
		}
			k=i;
			while(k<n) {
				System.out.print(" ");
				k++;
			}
			
			System.out.println();
		}
	}
}

这样就可以交差啦~~

有兴趣的同学可以到我公众号看看呀,还有其他实验报告可以一起互相学习啊~

课程设计也可以哦!~

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值