Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make a switch

    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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

            if (i%a==0) {
                b = 1-b;
            }
            if(b==1){
                System.out.print("X");
            }else {
                System.out.print("O");
            }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading