אשכול: עזרה ב Java.
View Single Post
ישן 28-02-08, 19:59   # 6
meshuga
הנהלת הפורום לשעבר
 
meshuga's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
גיל: 35
הודעות: 7,601

meshuga לא מחובר  

בניתי לך בדרך ה"מסורתית" שמלמדים:
קוד:
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));
	}
}
אם יש צורך בהסבר...תגיד לי..אני יסביר...
  Reply With Quote