Computer Applications
Write a program that displays all the numbers from 150 to 250 that are divisible by 5 or 6, but not both.
Java
Java Iterative Stmts
3 Likes
Answer
public class KboatFactorCheck
{
public static void main(String args[]) {
for (int i = 150; i <= 250; i++) {
int mod5 = i % 5;
int mod6 = i % 6;
if ((mod5 == 0 || mod6 == 0)
&& !(mod5 == 0 && mod6 == 0)) {
System.out.println(i);
}
}
}
}
Output
Answered By
2 Likes
Related Questions
Write a program in Java to read a number and display its digits in the reverse order. For example, if the input number is 2468, then the output should be 8642.
Output:
Enter a number: 2468
Original number: 2468
Reverse number: 8642Write a program in Java to read a number, remove all zeros from it, and display the new number. For example,
Sample Input: 45407703
Sample Output: 454773Write three different programs using for, while, and do-while loops to find the product of series 3, 9, 12,… 30.
Write a program to convert kilograms to pounds in the following tabular format (1 kilogram is 2.2 pounds):
Kilograms Pounds 1 2.2 2 4.4 20 44.0