Thursday, August 23, 2018

How to find largest number less than a given number and without a given digit?

For example, If given number 165 and given digit is 6 then you should find the largest number less than 165 but it should not contain 4 in it. In this case  answer is 159.


package com.altafjava.test;

public class FindLargestNo {
public static void main(String[] args) {
int givenNum=165;
int givenDigit=6;
for(int i=givenNum;i>=Integer.MIN_VALUE;i--){
if((i+"").contains(givenDigit+"")==false){
System.out.println(i);
break;
}
}
}
}

Note :-  double quotes(" ") is used to convert primitive data type into String 





How to find largest number less than a given number and without a given digit?







Share this

0 Comment to "How to find largest number less than a given number and without a given digit?"

Post a Comment