in Education by
hi friends hope you all are doing great Plz answer my question please do not give invalid answers Write a program in Java to check for the ugly number. Thank you Select the correct answer from above options

1 Answer

0 votes
by
Here is you answer // Java program to find nth ugly number class uglyno { /*This function divides a by greatest divisible power of b*/ static int maxDivide(int a, int b) { while(a % b == 0) a = a/b; return a; } /* Function to check if a number is ugly or not */ static int isUgly(int no) { no = maxDivide(no, 2); no = maxDivide(no, 3); no = maxDivide(no, 5); return (no == 1)? 1 : 0; } /* Function to get the nth ugly number*/ static int getNthUglyNo(int n) { int i = 1; // ugly number count int count = 1; // check for all integers // until count becomes n while(n > count) { i++; if(isUgly(i) == 1) count++; } return i; } /* Driver program to test above functions */ public static void main(String args[]) { int no = getNthUglyNo(150); System.out.println(“150th ugly “ + “no. is “+ no); } }

Related questions

0 votes
    Wt is coding classes please help me in this question give a valid answer please I will mark them brainlist and ... give valid answer. Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Write the following in while(): For (i=1;i =100;i++){Print( %d \ ,i);} (Will no one be able to solve ... as i am doing an exam now) Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    Give at least two to three differences between rint() and round() in Java… Please give the answer in points.. Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    hi friends .. good morning . ©Any 3 difference between Break statement and Continue statement ?? Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    PLEASE SEND THE ANSWER OF THIS QUESTION P_ N_ R_ V THIS IS COMPUTER DEVICE ANSWER Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    write a program to enter a sentence and check if it contains palindrome words or not. if yes then count and ... present. Java class 10 Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    program code for this question: Raju has a lot of strings but he does not like all of them.He likes only Swaggy ... at least K times. Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    convert the following into For loop; while(true) System.out.print(‘*’); (in java ) PLEASE ANSWER FAST… WILL MARK BRAINLIEST** Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    Name the class that is used for different mathematical functions.(in java) PLEASE ANSWER FAST URGENT HELP ... BRAINLIEST FOR SURE☆☆ Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    HI FREINDS HOW ARE YOU ALL GOOD WALA MORNING TO ALL …………………CAN U EXPLAIN NEWTON 3RD LAW Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    mention the following in terms of java 1 : values passed in method. 2 : array is passed in method. PLEASE ... BRAINLY MEMBER HELP..☆ Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    Heyy mates..Am an icse student can anyone tell me any importance for java please its urgent I have my exam ... please for icse java. Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Can you prepare question and answer for a computer quiz ?????? Pls Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    No spammers please do it clear (show your work also) and how the answer comes please… int m=2 and int n=15 for(int i=1;i...
asked Dec 23, 2021 in Education by JackTerrance
...