如何在Java方法中使用while循环并打印加法函数?

问题描述

| 我在上一个println中有问题。我希望它打印上一个字符串被打印的次数,并将所有数字加在一起。因此,如果用户输入\“ 3 \”,它将打印出三遍,然后将这三个数字加起来得到六个。 有人知道我该怎么做吗?还是我做错了什么?
    import java.util.Scanner;

    public class LoveCS { 
        public static void main(String[] args) { 
            int limit; 
            Scanner scan = new Scanner(System.in);
            System.out.println(\"How many times should the string be printed? \" );
            limit = scan.nextInt();  
            int count = 1; 
            while (count <= limit){ 
                System.out.println(+count+\"I love hot chocolate!!\"); 
                count++;    
            } 
            sum+=limit;
            System.out.println(\"Java printed this message: \"+ limit+ \" times.\" + \"The sum of the numbers from 1 to \" + (count-1) + \" is \" sum);

        } 
    } 
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)