import java.util.Scanner;
public class Main2 {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int a=scan.nextInt();
int b=1;
for (int i=1;i<=30;i++){
if(i%a==0){
b=1;
System.out.print("X");
}else {
System.out.print("O");
}
}
}
}
- I drive 3 into the scanner
- the desired result
- XXXOOOXXXOOOXXXOOOXXX
>Solution :
Try this:
if (i%a==0) {
b = 1-b;
}
if(b==1){
System.out.print("X");
}else {
System.out.print("O");
}