2017.11.27T19_8zuoye
Posted 晓……晓
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017.11.27T19_8zuoye相关的知识,希望对你有一定的参考价值。
package com.whxiong8;
import java.util.*;
public class Practise8 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("第一题");
System.out.println("*******************************");
System.out.println("请输入您想打印的行数:");
int num = input.nextInt();
for (int i = 0; i < num; i++) {
for (int j = 0; j <= i; j++) {
System.out.print((j + 1) + " ");
}
System.out.println("\n");
}
System.out.println("\n");
System.out.println("第二题");
System.out.println("*******************************");
int i; // 公鸡数
int j; // 母鸡数
int k; // 皱鸡数
for (i = 0; i <= 20; i++) {
for (j = 0; j <= 33; j++) {
k = 100 - i - j;
if (k % 3 == 0 && 5 * i + 3 * j + k / 3 == 100) {
System.out.println("公鸡数为" + i + "只时" + "\t母鸡数为" + j + "只\t"
+ "皱鸡数为" + k);
}
}
}
System.out.println("\n");
System.out.println("第三题");
System.out.println("*******************************");
int[] class1 = new int[3];
int[] student = new int[4];
double score = 0;
int total = 0;
double sum = 0;
for (int n = 0; n < class1.length; n++) {
System.out.println("请输入" + (n + 1) + "班学生的成绩");
for (int m= 0; m< student.length; m++) {
System.out.println("\t请输入第" + (m + 1) + "名学生的成绩:");
System.out.print("\t");
score = input.nextDouble();
while (score > 100 || score < 0) {
System.out.println("\t输入错误,请重新输入成绩:");
System.out.print("\t");
score = input.nextDouble();
}
if (score >= 85) {
sum += score;
total++;
}
}
}
double age = sum / total;
System.out.println("成绩大于85分的学生为:" + total);
System.out.println("成绩大于85分学生的平均分为:" + age);
System.out.println("\n");
System.out.println("第四题");
System.out.println("*******************************");
int cipher = 111111;// cipher为用户初始密码
int num1 = 0;// 用户从键盘输入密码
int money = 0;// 用户输入的取款金额
System.out.println("请您输入六位数密码:");
num1 = input.nextInt();
for (int n = 3; n > 1; n--) {
if (num1 != cipher) {
System.out.println("密码输入错误,您还有" + (n - 1) + "次机会,请重新输入:");
num1 = input.nextInt();
}
if (num1 == cipher) {
System.out.println("请输入您的取款金额:");
money = input.nextInt();
while (money % 100 != 0 || money > 1000 || money < 0) {
System.out.println("您输入金额的金额不合法,请重新输入:");
money = input.nextInt();
}
if (money >= 0 && money <= 1000 && money % 100 == 0) {
System.out.println("您取了" + money + "元");
break;
}
}
}
System.out.println("交易完成请取卡!");
System.out.println("\n");
System.out.println("第五题");
System.out.println("*******************************");
System.out.println("请输入您要打印菱形的行数(奇数):");
int rows = input.nextInt();
while (rows % 2 == 0) {
System.out.println("请重新输入行数(奇数):");
rows = input.nextInt();
}
for (int n = 1; n <= (rows + 1) / 2; n++) {
for (int m = 1; m <= (rows + 1) / 2 - n; m++) {
System.out.print(" ");
}
for (int x = 1; x <= 2 * n - 1; x++) {
System.out.print("*");
}
System.out.print("\n");
}
for (int n = 1; n <= (rows - 1) / 2; n++) {
for (int m = n; m >= 1; m--) {
System.out.print(" ");
}
for (int x = rows - 2 * n; x >= 1; x--) {
System.out.print("*");
}
System.out.print("\n");
以上是关于2017.11.27T19_8zuoye的主要内容,如果未能解决你的问题,请参考以下文章