Copy the program and circle each error and write the correct program beside it (i will upvote after) Java program to che

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Copy the program and circle each error and write the correct program beside it (i will upvote after) Java program to che

Post by answerhappygod »

Copy the program and circle each error and write the correctprogram beside it (i will upvote after)
Java program to check whether a given number is an uglynumber.
In number system, ugly numbers arepositive numbers whose only prime factors are 2, 3 or 5. First 10ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. By convention, 1is included.
Test Data: Input an integer number: 235
import java.util.Scanner;
public class Exercise1 {
public static voidmain(String[] args){
Scanner in = newScanner(System.in);
System.out.print("Inputan integer number: ");
int n =in.nextInt();
if (n <= 0){
System.out.print("Inputa correct number.");
}
int x = 0;
while (n != 1){
if(n % 5 == 0) {
n/= 5;
}else if (n % 3 == 0) {
n/= 3;
}else if (n % 2 == 0) {
n/= 2;
}else {
System.out.print("Itis not an ugly number.");
x = 1;
break;
}
}
if (x==0)
System.out.print("It is anugly number.");
System.out.print("\n");
}
}
Output:
Input an integer number:235
It is not an ugly number.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply