(LOW LEVEL PROGRAMMING) his program is to iterate through a set of integers (1-5
ID: 3703314 • Letter: #
Question
(LOW LEVEL PROGRAMMING) his program is to iterate through a set of integers (1-500) and output one of four outputs depending on the number: if the number is divisible (no remainder) by 3, then the output is "FEED." If the number is evenly divisible by 4, then the output is "BABE." If the output is divisible by both 3 and 4, then the output should be "FEEDBABE". Lastly, if the output is not divisible by either 3 or 4, then the number itself should be printed. Each entry is on its own line. You will be submitting both the code and the output. Program iterates through the integers 1 to 500 If the number is divisible by 3 output: FEED If the number is divisible by 4 output: BABE . If the number is divisible by both 3 and 4 output: FEEDBABE e If the number is NOT divisible by either 3 or 4 output the number itself This program will generate a file with 500 lines in the output. Below is the output of the code run from the number 1 to 25 demonstrating what the output should look like (further output is truncated to prevent this lab description from being too longl): FEED BABE FEED BABE FEEDExplanation / Answer
Java Code :
import java.io.*;
public class A
{
public static void main(String arg[])
{
for(int i=1;i<=500;i++) // iterating 500 times from 1 to 500
{
if(i%3==0) // condition 1
System.out.println("FEED");
else if(i%4==0) // condition 2
System.out.println("BABE");
else if(i%3==0 && i%4==0) // condition 3
System.out.println("FEEDBABE");
else // condition 4 ( otherwise )
System.out.println(i);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.