Java 按用户定义的次数打印一对静态方法?

Java 按用户定义的次数打印一对静态方法?,java,Java,在学校的计算机科学课上,我必须编写一个java代码,要求用户输入图腾pol上的一些数字。输出必须达到指定的位数(可能更小,具体取决于数字)。输出必须有1只鹰在顶部,鲸鱼人像按顺序配对。这就是我所拥有的,但当我输入2时,程序会打印3个数字。帮忙 import java.util.*; //For scanner. /* * The class Totem contains methods to print a totem pole * with up to the amount of figur

在学校的计算机科学课上,我必须编写一个java代码,要求用户输入图腾pol上的一些数字。输出必须达到指定的位数(可能更小,具体取决于数字)。输出必须有1只鹰在顶部,鲸鱼人像按顺序配对。这就是我所拥有的,但当我输入2时,程序会打印3个数字。帮忙

import java.util.*; //For scanner.

/*
* The class Totem contains methods to print a totem pole
* with up to the amount of figures specified by the user.
* 1 eagle always on top of pole.
* Whale and human figures paired with human below whale.
*/
public class Totem {
    //Welcome to the main method.
    public static void main(String args[]) {
        Scanner console = new Scanner(System.in);//initiates new scanner.
        System.out.println();
        System.out.println("This program displays a totem pole with the amount of figures you want!");
        System.out.println("How many figures do you want?");
        int numberOfFigures = console.nextInt();
        eagle();
        for (int i = 0; i < numberOfFigures / 2; i++) {
            whaleHumanPair();
        }
    }

//Prints ASCII art of an eagle.
public static void eagle() {
    System.out.println("                      _--_");
    System.out.println("                     /   -)");
    System.out.println("                 ___/___|___");
    System.out.println("       ____-----///|     ||||~=---_____");
    System.out.println("     //~/////////~/|     |//|||\\\\\\\\\\\\\\\\\\\\");
    System.out.println("   /////////////////|   |/////|\\\\\\\\\\\\\\\\\\\\\\\\");
    System.out.println("  /////~~~~~~~~~~~~\\ |.||/~~~~~~~~~~~~`\\\\\\\\\\ ");
    System.out.println(" //                /\\\\|\\\\                  \\\\");
    System.out.println("                  ///W^\\W\\");
    System.out.println("                 ////|||\\\\\\");
    System.out.println("                 ~~~~~~~~~~");
}
//Prints ASCII art of a whale.
public static void whale() {
    System.out.println(" .--------'```'----....,,______             _,");
    System.out.println("|                               `-------._./  \\");
    System.out.println("|                                             <");
    System.out.println("\\          .-'`'-.                             `");
    System.out.println(" \\          -.o_.     _                 -'`\\   /");
    System.out.println("  ``'--.._.-=-._    .'  \\        _,,--'`    ._(");
    System.out.println(" (^^^^^^^`___    '-. |    \\  ,,.-'");
    System.out.println("  ````````   `'--..___\\    |`");
    System.out.println("                      `-.,'");
}

//Prints ASCII art of a human.
public static void human() {
    System.out.println("                 ////|||\\\\\\\\");
    System.out.println("                //// ^ ^ \\\\\\\\");
    System.out.println("                ||/  @ @  \\||");
    System.out.println("                ||    \"    ||");
    System.out.println("                ||\\   -   /||");
    System.out.println("                ~~ `). .(' ~~");
    System.out.println("               /---'|   |---\\");
    System.out.println("             /'  ,  `\\-/'. ,  '\\");
    System.out.println("            (   \\ |.  ..  | /   )");
    System.out.println("             \\  _\\|  .  . |/_  /");
    System.out.println("              `(  >.  .   <  )'");
    System.out.println("                \" |  .  . | \"");
    System.out.println("                  |  .    |");
    System.out.println("                  |    .  |");
    System.out.println("                  | .    .|");
    System.out.println("                  |%%%%%%%|");
    System.out.println("                  __|#|#|__");
    System.out.println("                 (____|____)");   
}

public static void whaleHumanPair() {
    whale();
    human();
}
import java.util.*//用于扫描仪。
/*
*类Totem包含打印图腾柱的方法
*最多为用户指定的数字量。
*一只鹰总是在杆子的顶端。
*鲸鱼和人像与鲸鱼下面的人配对。
*/
公共阶级图腾{
//欢迎使用主方法。
公共静态void main(字符串参数[]){
扫描仪控制台=新扫描仪(System.in);//启动新扫描仪。
System.out.println();
println(“这个程序显示一个图腾柱,上面有你想要的数字数量!”);
System.out.println(“您想要多少数字?”);
int numberOfFigures=console.nextInt();
鹰();
对于(int i=0;iSystem.out.println(“|一个数字代表
eagle();
之前的
代表
,另外两个数字代表
whaleHumanPair
的一次。也许你会想要分开这对。

这是因为循环:

for (int i = 0; i < numberOfFigures / 2; i++) {
    whaleHumanPair();
}

如果我理解正确,两个数字你想要一只鹰和一只鲸鱼

只有成对的(鲸鱼,人类)需要按顺序排列

所以,你应该在你的循环中处理好机会和机会

int numberOfFigures = console.nextInt();
if (numberOfFigures > 0) {
    eagle();              // i == 0
    for (int i = 1; i <= numberOfFigures; i++) {
        if (i % 2 != 0) { // odd, i == 1, 3, ...
            whale();
        } else {          // even, i == 2, 4, ...
            human();
        }
    }
}
int numberOfFigures=console.nextInt();
如果(numberOfFigures>0){
eagle();//i==0

for(int i=1;i Eagle+Whale+Human=3位数字。有什么问题吗?嗯,…for循环运行得太频繁了一次。你能做些什么来解决这个问题?@Henry怎么办?
numberOfFigures/2=2/2=1
,所以循环运行once@cricket_007是的,但对于2 OP的输入,只需要一个数字(即一只鹰).@Henry或者可能只是一只鹰和一只鲸鱼?
int numberOfFigures = console.nextInt();
if (numberOfFigures > 0) {
    eagle();              // i == 0
    for (int i = 1; i <= numberOfFigures; i++) {
        if (i % 2 != 0) { // odd, i == 1, 3, ...
            whale();
        } else {          // even, i == 2, 4, ...
            human();
        }
    }
}