Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
根据用户输入的数字,制作一个显示星号的简单程序的代码是什么。我希望它像这样

Enter 1st Integer:2
Enter 2nd Integer:3
Enter 3rd Integer:4
Enter 4th Integer:5


这将是结果

1st Integer:**
2nd Integer:***
3rd Integer:****
4th Integer:*****


就这么简单,我在这段代码上遇到了问题,我只需要循环即可。

最佳答案

int inputNumber = 2;
StringBuilder asteriskBuilder = new StringBuilder();

for (int i = 0; i < inputNumber; ++i) {
    asteriskBuilder.append("*");
}

//  1st Integer:**
System.out.println("1st Integer:" + asteriskBuilder);

关于java - 根据输入的数字显示星号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22437020/

10-11 07:40