第八天作业

练习一<贵妃减肥记>
public class day7_04 {
public static void main(String[] args) {
double tz=170.0;
int ts=0;
System.out.println(“贵妃减肥记”);
while(tz>99.9){
ts+=1;
if(ts6||ts17){
tz+=4;
System.out.println(“与皇上出去玩了,共进晚餐,吃的烤全羊,体重大增,现在”+tz+“斤”);
continue;
}else if(ts==10){
System.out.println(“减肥的时候摔跤了,今天不能减肥了,现在”+tz+“斤”);
continue;
}
tz-=0.8;
System.out.println(“运动第”+ts+“天,现在”+tz+“斤”);
}
System.out.println("*用了"+ts+“天”);
System.out.println("*用了"+ts/7+“周”);
}
}

123456789101112131415161718192021222324练习二录入成绩import java.util.Scanner;
public class day7_05{
public static void main(String[]args){
int times=6;
double avg=0;
int chengji=0;
int zonghe=0;
Scanner a=new Scanner(System.in);
for(int i=1;i<times;i++){
System.out.println(“请输入第”+i+“个成绩”);
chengji=a.nextInt();
if(chengji<0){
System.out.println(“录入错误,重新录入”);
i–;
}
zonghe=zonghe+chengji;
}
System.out.println(“总和为”+zonghe);
avg=zonghe/5.0;
System.out.println(“平均分为”+avg);
}
}
12345678910111213141516171819202122练习三游戏程序import java.util.Scanner;
public class day7_06 {
public static void main(String[] args) {
Scanner b=new Scanner(System.in);
System.out.println(“Loading…游戏加载中");
System.out.println(“请选择你要登录的方式:\n1.微信登陆\n2.QQ登陆\n3.游戏通行证登陆");
int jc=0;
int jc2=0;
int df=0;
while(jc0){
String dl=b.next();
if(dl.equals(“1”)||dl.equals(“2”)||dl.equals(“3”)){
System.out.println("*登录成功");
jc=1;
break;
}else{
System.out.println("*请重新选择登录方式:\n1.微信登陆\n2.QQ登陆\n3.游戏通行证登陆");
}
}
while(true){
System.out.println("*选择游戏模式:\n1.三对三\n2.五对五");
String yx=b.next();
if(yx.equals(“1”)){
System.out.println("*已选择游戏模式:三对三");
jc2=1;
while(jc2
1){
df=80+(int)(Math.random()
(100-80+1));
System.out.println(”
<三对三>本局得分:”+df);
System.out.println("*是否继续当前游戏(y)——(输入其他)重新选择游戏模式");
String a=b.next();
if(a.equals(“y”)){
System.out.println("*继续游戏<三对三>");
}else{
System.out.println(“重新选择游戏模式");
break;
}
}
}else if(yx.equals(“2”)){
System.out.println(“已选择游戏模式:五对五");
jc2=2;
while(jc2==2){
df=160+(int)(Math.random()
(200-160+1));
System.out.println(”
<五对五>本局得分:”+df);
System.out.println("*是否继续当前游戏(y)——(输入其他)重新选择游戏模式");
String a=b.next();
if(a.equals(“y”)){
System.out.println("*继续游戏<五对五>");
}else{
System.out.println("*重新选择游戏模式");
break;
}
}
}else{
System.out.println("*请重新选择游戏模式:\n1.三对三\n2.五对五");
}
}
}
}

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859

第八章的作业主要是关于字符串和列表、元组的操作。对于字符串,可以使用索引和切片来获取和修改字符串中的字符,还可以使用内置函数,如len()来获取字符串的长度,以及count()、index()等函数来统计字符出现的次数和找出字符的位置。 对于列表和元组,可以使用索引和切片来获取和修改列表和元组中的元素,还可以使用内置函数,如len()来获取列表和元组的长度,以及count()、index()等函数来统计元素出现的次数和找出元素的位置。 作业可能包括以下内容: 1. 使用字符串的切片和索引操作,截取出指定的子字符串; 2. 使用字符串的内置函数,如count()、index()等来统计指定字符的出现次数和位置; 3. 使用列表的索引来获取和修改指定的元素; 4. 使用列表的切片操作,截取出指定的子列表; 5. 使用列表的内置函数,如append()、count()等来添加元素和统计指定元素的出现次数; 6. 使用元组的索引来获取指定的元素; 7. 使用元组的切片操作,截取出指定的子元组; 8. 使用元组的内置函数,如count()、index()等来统计指定元素的出现次数和位置。 为了完成第八章的作业,我们需要熟悉字符串、列表和元组的基本操作和内置函数的使用。可以通过阅读和理解教材中的相关知识点和示例代码,然后按照作业的要求进行编写和测试。编写过程中需要注意细节和语法的正确性,同时也可以参考官方文档和其他相关资料进行查找和学习。完成作业后,可以将代码保存并运行,然后检查输出结果是否符合预期。如果有错误或不清楚的地方,可以再次阅读教材或者寻求帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值