第8章课后作业

第1题   图形打印

import java.util.Scanner;
public class HomeWork8_2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入行数:");
int rows = input.nextInt();
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println("");
}
input.close();
}

}

第2题   百钱买百鸡

public class HomeWork8_3 {
public static void main(String[] args) {
for (int i = 0; i <= 20; i++) {
for (int j = 0; j <= 30; j++) {
for (int k = 0; k < 100; k++) {
if (5 * i + 3 * j + k / 3 == 100 && i + j + k == 100 && k % 3 == 0) {
System.out.println("公鸡有:" + i + " 母鸡有:" + j + " 小鸡有:" + k);
}
}
}
}
}
}

第3题   从控制台输入三个班级各四名学员的成绩,并统计所有大于85分的学员平均分

public class HomeWork8_4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int score = 0;
int sum = 0;
int peopleNum = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
System.out.print("请输入第" + (i + 1) + "班的第" + (j + 1) + "个学生的成绩:");
score = input.nextInt();
if (score > 85) {
sum += score;
peopleNum++;
continue;
}
}
}
double avg = sum / peopleNum;
System.out.println("其中大于85分的学员平均分是:" + avg);
input.close();
}
}

第4题   编程实现银行ATM取款过程

import java.util.Scanner;


public class HomeWork8_5 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = 0;
for (int i = 0; i < 3; i++) {
System.out.print("请输入密码:");
int password = input.nextInt();
if(password==111111) {
break;
}else {
num++;
continue;
}
}
if(num==3) {
System.out.println("输入次数超过三次,请取卡!");
}
if(num<3) {
System.out.print("请输入金额:");
int money = input.nextInt();
while (money%100!=0||money<0||money>1000) {
System.out.print("输入金额不合法,请重新输入:");
money = input.nextInt();
}
System.out.println("您取了"+money+"元");
System.out.println("交易完成,请取卡!");
}input.close();
}
}

第5题   打印菱形

import java.util.Scanner;

public class HomeWork8_5 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = 0;
for (int i = 0; i < 3; i++) {
System.out.print("请输入密码:");
int password = input.nextInt();
if(password==111111) {
break;
}else {
num++;
continue;
}
}
if(num==3) {
System.out.println("输入次数超过三次,请取卡!");
}
if(num<3) {
System.out.print("请输入金额:");
int money = input.nextInt();
while (money%100!=0||money<0||money>1000) {
System.out.print("输入金额不合法,请重新输入:");
money = input.nextInt();
}
System.out.println("您取了"+money+"元");
System.out.println("交易完成,请取卡!");
}input.close();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值