It is possible to print this with "for" or some other way

0
package seguimiento;

public class Asteriscos {

    public static void main(String[] args) {
        Asteriscos objAsteriscos=new Asteriscos();
        objAsteriscos.imprimirAsteriscos();

    }
    public void imprimirAsteriscos() {
        System.out.println("*****************");
        System.out.println(" *****************");
        System.out.println("*****************");
        System.out.println(" *****************");
        System.out.println("*****************");
        System.out.println(" *****************");


    }
}
    
asked by santiago londoño velez 06.03.2018 в 01:10
source

2 answers

0

Yes, you can do it with a for putting in the function:

for(i=0 ; i<6 ; i++){
   if(i%2==0){
      System.out.println("*****************");
} else {
      System.out.println(" *****************");
}
    
answered by 06.03.2018 / 01:37
source
1

If your question is how to print on the screen alternate lines that are the same every two lines, you can do it with a for simply looking if it is even or odd, and printing accordingly:

for(int i = 0; i < N; i++){ // N es el numero de lineas que quieres escribir
    if(i%2 == 0) // Si es par
        System.out.println("*****************");
    else // Si es impar
        System.out.println(" *****************");
}
    
answered by 06.03.2018 в 01:36