samedi 6 novembre 2021

Java : for loop and if statement [closed]

Write a method with one integer argument. It will print from 1 to the value of the argument in console. Finally invoke the method.

package day6;

public class Homeworkloop {

public static void main(String[] args) {
    print (20);
    for (int i=1;i<=20;i=i+1) {
        System.out.println(i);
    }
}

public static void print (int x) {
    System.out.println(x);
}

}

Aucun commentaire:

Enregistrer un commentaire