dimanche 21 février 2016

How to display all numbers between a range, but every 3rd number is changed to an asterisk

Just wondering how I do this, here is my code so far, but I can't seem to get it working, it shows all the numbers between 1-12 and adds the asterisk before the 3rd number, while still showing the 3rd number.

public class Help {

public static void main(String[] args) {
    int i = 1;

    while(i < 12){
    System.out.println(i);
    i = i + 1;

    if(i % 3 == 0){
        System.out.println("*");
      }
    }
  }
}

Aucun commentaire:

Enregistrer un commentaire