Java程序按顺序打印数字

Java程序按顺序打印数字,java,Java,我正在用数字写这个程序,但是我被卡住了,需要一些帮助 迄今为止的代码: public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Oppgi øvre grense: "); int Number = in.nextInt(); int tall = 1; for(int t = 0; tall <=45; tall

我正在用数字写这个程序,但是我被卡住了,需要一些帮助

迄今为止的代码:

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Oppgi øvre grense: ");
    int Number = in.nextInt(); 
    int tall = 1;
    for(int t = 0; tall <=45; tall++){
            System.out.println(" " + tall);
    }   
}
publicstaticvoidmain(字符串[]args){
扫描仪输入=新扫描仪(系统输入);
系统输出打印(“Oppgiøvre grense:”);
int Number=in.nextInt();
int-tall=1;
对于(int t=0;高)
这里有两个不同的任务:
1.决定一行打印多少个数字
2.实际打印数字

既然如此,一个循环决定要打印多少个数字:外循环。之所以是外循环,是因为在实际打印之前,您需要清楚地知道需要打印多少个数字。
另一个循环:内部循环进行实际打印

因此,一旦从外循环开始,内循环将开始打印。
然后,它将查看是否已打印该通行证的最大号码数。
如果是,停止。然后,增加外部循环。返回,打印,检查,然后执行相同的操作


够简单吗?

记录行号 e、 g

int line=1;//行号
int count=0;//行上的数字数
对于(int x=0;x
公共类RareMile{
公共静态void main(字符串[]args){
printNum(5);
}
公共静态void printNum(int n){
int k=1,sum=0;

对于(int i=1;i)您需要另一个内部循环。
outer loop{
    decides number of numbers in one line
    inner loop{
        prints actual numbers.
        Please keep track of the numbers you have printed so far
        Inner loop starts at numbers printed so far
        It will have passes = number of numbers to print
    }
}  
int line = 1; // line number
int count = 0; // number of numbers on the line
for(int x = 0; x <= 45; x++){
    if (count == line){
        System.out.println(""); // move to a new line
        count = 0; // set count back to 0
        line++; // increment the line number by 1
    }
    System.out.print(x); // keep on printing on the same line
    System.out.print(" "); // add a space after you printed your number
    count++;
}
public class RareMile {

    public static void main (String[] args){
        printNum(5);
    }

    public static void printNum (int n){
        int k=1, sum=0;
        for (int i=1; i<=n; i++){
            sum=0;
            for(int j=1; j<=i; j++){    
                System.out.print(k);
                sum = sum+k;
                k++;                
                }
            System.out.print("            =" + sum);
            System.out.println();
        }        
    }

}