JavaRush /בלוג Java /Random-HE /בעיות לוגיות בראיון
Юрий Кузнецов
רָמָה
Москва

בעיות לוגיות בראיון

פורסם בקבוצה
אתה צריך לנתח ממני 5 בעיות לוגיות ועוד 4 בעיות Java. בעיות שנתקלו במהלך ראיונות ופתרונות להן זמינים באינטרנט. אני אתן את הרשימה המובילה של אלה שנתקלתי בהם במהלך ראיונות. בעיות לוגיות בראיון - 1
  1. ארבעה אנשים עם כובעים

  2. בעיה לגבי גשר ופנס

  3. מתוך 9 מטבעות, אחד מזויף: הוא קל יותר. איך מוצאים אותו בשתי שקילות על המשקל?

  4. כמעט זהה לבעיה הקודמת, רק המאזניים יכולים להיות כל אחד. בעיה "5 צנצנות גלולות" .

  5. "רכבת אינסופית"

כדי לכסות את השאלות שנשאלו במהלך הראיונות:

  1. כתוב מספר דרכים ליישם סינגלטון ב-java.

  2. מה יקרה בקוד הזה?

    בעיות לוגיקה בראיון - 2
    class MyExc1 extends Exception{}
    class MyExc2 extends Exception{}
    class MyExc3 extends Exception{}
    
    public class Test {
        public static void main(String[] args) throws Exception {
            try {
                System.out.print(1);
                p();
            }catch (MyExc2 e){
            }
            finally {
                throw new MyExc3();
                System.out.print(2);
            }
        }
        public static void p() throws Exception {
            try {
                throw new MyExc1();
                 } catch (MyExc1 myExc1) {
                throw new MyExc2();
            }finally {
                System.out.println(3);
            }
        }
    }
  3. בעיה ממני, כי אני לא זוכר איזו דוגמה הייתה

    public class Test {
        public static void main(String[] args)  {
            String s = "Hello";
            String s1 = "Hello";
            String s2 = new String("Hello");
    
            System.out.println(s == s1);
            System.out.println(s1 == s2);
    
            Integer i = 111;
            Integer i1 = 111;
            Integer i2 = new Integer(111);
            Integer i3 = new Integer(111);
    
            Integer i4 = -129;
            Integer i5 = -129;
            Integer i6 = new Integer(-129);
    
            System.out.println(i == i1);
            System.out.println(i1 == i2);
            System.out.println(i2 == i3);
    
            System.out.println(i4 == i5);
            System.out.println(i5 == i6);
    
            System.out.println(i6 == -129);
        }
    }
  4. מה תהיה התוצאה של הפעלת התוכנית? ואיזו תוצאה נקבל אם נבטל את ההערות לשתי השורות האחרונות?

    class Test{
        private int id;
        private Integer id2;
    
        public Test(int id, Integer id2) {
            System.out.println("Создаем екзепляр Test");
            this.id = id;
            this.id2 = id2;
        }
    
        public Integer doIt(){
            return id + id2;
        }
    }
    class Test1{
        private Test test;
        private static int i;
    
        public Test1() {
            System.out.println("Создаем екзепляр Test1");
            this.test = new Test(i, 10);
        }
        public Test getTest() {
            return test;
        }
    }
    
    class Main {
        public static void main(String[] args)  {
            Test1 test1 = new Test1();
            System.out.println(test1.getTest().doIt());
           // Test test = new Test(null, 1);
           // test.doIt();
        }
    }
    בעיות לוגיקה בראיון - 3
נ.ב: תשובות לבעיות לוגיות ניתן למצוא באינטרנט. למעוניינים, אני מצרף פוסט קודם על ראיונות למפתחי Java
הערות
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION