בניתי לך בדרך ה"מסורתית" שמלמדים:
קוד:
public class Hosts
{
public static int tryThis(int num,int x){
boolean is=false;
int t=num;
while(t>0 && !is){
if(t%10==x)
is=true;
t/=10;
}
if(!is)
num=num*10+x;
return num;
}
public static void main(String[] args){
System.out.println(tryThis(12345,5));
System.out.println(tryThis(12345,6));
}
}
אם יש צורך בהסבר...תגיד לי..אני יסביר...