Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that prints asks the user to enter a positive value (1 less

ID: 668106 • Letter: W

Question

Write a Java program that prints asks the user to enter a positive value (1 less than or equal to 200) and print each number up to that line, 1 per line with the following changes (SNAP CRACKLE POP).

If a number is divisible by 2 (but not 3 or 5) print out SNAP instead of the integer.

If a number is divisible by 3 (but not 2 or 5) print out CRACKLE instead of the integer.

If a number is divisible by 5 (but not 2 or 3) print out POP instead of the integer.

If a number is divisible by 2 and 3 (but not 5) print out SNAPCRACKLE instead of the integer.

If a number is divisible by 2 and 5 (but not 3) print out SNAPPOP instead of the integer.

If a number is divisible by 3 and 5 (but not 2) print out CRACKLEPOP instead of the integer.

If a number is divisible by 2, 3, and 5 print out SNAPCRACKLEPOP instead of the integer.

Explanation / Answer

import java.io.*;

class prg
{
   public static void main(String args[])
   {
       int n,i;

       DataInputStream o = new DataInputStream(system.in);
       System.out.println("Enter Positive number less than 200");
       String s1=o.readLine();

       n= Integer.parseInt(s1);

       for(i=1;i<=n;i++)
       {
           System.out.println(i);
       }

       if(n%2==0 && n%3 !=0 && n%5!=0)
       {
           System.out.println("SNAP");
       }

       if(n%2!=0 && n%3 ==0 && n%5!=0)
       {
           System.out.println("CRACKLE");
       }

       if(n%2!=0 && n%3 !=0 && n%5==0)
       {
           System.out.println("POP");
       }

       if(n%2==0 && n%3 ==0 && n%5!=0)
       {
           System.out.println("SNAPCRACKLE");
       }

       if(n%2==0 && n%3 !=0 && n%5==0)
       {
           System.out.println("SNAPPOP");
       }

       if(n%2!=0 && n%3 ==0 && n%5==0)
       {
           System.out.println("CRACKLEPOP");
       }

       if(n%2==0 && n%3 ==0 && n%5==0)
       {
           System.out.println("SNAPCRACKLEPOP");
       }

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote