[Solved] it was like a fibonacci I can’t figure out the code for this


This the Kotlin code which does what you want (it was easier for me to develop it this way):

import java.util.*

fun main(args: Array<String>) {
    val input = Scanner(System.`in`)

    print("Please enter a number range: ")
    val numOfCols = input.nextInt()

    print("Please enter a number of rows: ")
    val numOfRows = input.nextInt()

    for (i in 1..numOfRows) {
        for (j in 1..numOfCols){
            for (k in 1..numOfCols){
                if (k == i) {
                    print(k+j-1)
                } else {
                    print(1)
                }
            }
            print(" ")
        }
        println("")
    }
}

and this is the Java equivalent:

import java.util.*;

public class MyClass {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.print("Please enter a number range: ");
        int numOfCols = input.nextInt();

        System.out.print("Please enter a number of rows: ");
        int numOfRows = input.nextInt();

        for (int i = 1; i <=numOfRows; i++) {
            for (int j = 1; j <= numOfCols; j++){
                for (int k = 1; k <= numOfCols; k++){
                    if (k == i) {
                        System.out.print(k+j-1);
                    } else {
                        System.out.print(1);
                    }
                }
                System.out.print(" ");
            }
            System.out.println("");
        }
    }
}

3

solved it was like a fibonacci I can’t figure out the code for this