将整数显示为Xs的输出

时间:2014-08-08 18:49:48

标签: java string integer

所以,我对Java语言很陌生,并且在完成家庭作业时遇到了问题。我需要从用户那里获取控制台输入并将数字显示为Xs行。 (即“Pam出售的汽车> 3”将显示“Pam XXX” 这是我到目前为止所拥有的。一旦我接到if语句,我就不知道下一步该怎么做了。我试图查找许多不同的分辨率,但找不到任何描述我需要做什么的东西。 任何帮助将不胜感激。

import java.util.Scanner;

public class BarGraph2
{
    public static void main(String[] args)
    {

    int pam;
    int leo;
    int kim;
    int bob;

    Scanner p = new Scanner(System.in);
        System.out.print("Enter number of cars sold by Pam > ");        
        pam = p.nextInt();

    Scanner l = new Scanner(System.in);
        System.out.print("Enter number of cars sold by Leo > ");        
        leo = l.nextInt();

    Scanner k = new Scanner(System.in);
        System.out.print("Enter number of cars sold by Kim > ");        
        kim = k.nextInt();

    Scanner b = new Scanner(System.in);
        System.out.print("Enter number of cars sold by Bob > ");        
        bob = b.nextInt();

    System.out.println("\nCar Sales for the Month:");

    if(pam > 0)
        {   
            String pamSales = valueOf(int pam);

            pamSales.setLength

            System.out.print( "\nPam  " + pamSales);
        }
    else
        {
            System.out.print("\nPam  ");
        }

    }


}

编辑:我终于明白了...我觉得我的大脑刚刚被炒了?谢谢你们。

1 个答案:

答案 0 :(得分:0)

只需运行如下循环: -

System.out.print("PAM");    
for(int i=0;i<n;i++)    // here n is the required number of repetition
System.out.print("X");