self
Maths Puzzle
Q. The below Java program prints the numbers from 1 to 50. But for multiples of three print "DNA" instead of the number and for the multiples of five print "RNA". For numbers which are multiples of both three and five print "ATGC". Please identify the three bugs in the code and suggest how they can be resolved.
public class SeqTest {
public static void main(String args[]) {
for(int i = 1; i
Read Solution (Total 2)
-
- Bug 1: condition “else if(i%(3+5)==0)” should be replaced with “if(i%3==0&&i%5==0)”
Bug 2: condition if(i%3==0&&i%5==0) should be first line in the program.
Bug 3: Last line should be System.out.println(i); instead of System.out.println(“1 to 50”); - 8 years agoHelpfull: Yes(1) No(0)
- public class SeqTest {
public static void main(String args[]) {
for(int i = 1; i - 11 years agoHelpfull: Yes(0) No(2)
self Other Question