JAVA test on P6

Multiple choice questions about Java programming give you useful knowledge. If you love Java programming, don't skip the series of interesting tests below by Network Administrator.

  1. Question 1. Which line is wrong?
     1. int i = 0; 

    2. due to {

    3. i + = 1;

    4.} while (i == 0);

    5. System.out.println ('i =' + i);
    1. first
    2. 2 and 3
    3. 4
    4. No wrong lines
  2. Question 2. s is the result of how much when executing the command block?
     int i = 0; 

    int s = 0;

    for (;;) {

    if i == 3 break;

    s = s + i;

    i ++;

    }
    1. 6
    2. 3
    3. Program reported an error
    4. 0
  3. Question 3. In what line is the program wrong?
     1. int i = 0; 

    2. int s = 0;

    3. for (;;) {

    4. if i == 3 break;

    5. s = s + i;

    6. i ++;

    7.}
    1. 1 and 2
    2. 4
    3. 6
    4. No wrong lines
  4. Question 4. What is the result of the program?
     BreakDemo class { 

    public static void main (String [] args) {

    int [] arrayOfInts = {32, 87, 3, 589, 12, 1076, 2000, 8, 622, 127};

    int searchFor = 12;

    int i;

    boolean fountIt = false;

    for (i = 0; i
    if (arrayOfInts [i] == searchFor) {

    fountIt = true;

    break;

    }

    }

    if (fountIt) {

    System.out.println ('Found' + searchFor + 'at index' + i);

    } else

    System.out.println (searchFor + 'not in the array');

    }

    }
    1. 12 không phải trong mảng
    2. Found 12 at index 4
    3. Program error
      1. Found it
  5. Question 5. Which line is wrong?
     1. BreakDemo class { 

    2. public static void main (String [] args) {

    3. int [] arrayOfInts = {32, 87, 3, 589, 12, 1076, 2000, 8, 622, 127};

    4. int searchFor = 12;

    5. int i;

    6. boolean fountIt = false;

    7. for (i = 0; i
    8. if (arrayOfInts [i] == searchFor) {

    9. fountIt = true;

    10. break;

    11.}

    twelfth. }

    13. if (fountIt) {

    14. System.out.println ('Found' + searchFor + 'at index' + i);

    15.} else

    16. System.out.println (searchFor + 'not in the array');

    17.}

    18.}
    1. 2 and 6
      1. 3 and 11, 15
      1. 5, 7, 9
    2. No programs are wrong
  6. Question 6. What does the program do?
     BreakDemo class { 
    public static void main (String [] args) {
    int [] arrayOfInts = {32, 87, 3, 589, 12, 1076, 2000, 8, 622, 127};
    int searchFor = 12;
    int i;
    boolean fountIt = false;
    for (i = 0; i if (arrayOfInts [i] == searchFor) {
    fountIt = true;
    break;
    }
    }
    if (fountIt) {
    System.out.println ('Found' + searchFor + 'at index' + i);
    } else
    System.out.println (searchFor + 'not in the array');
    }
    }
    1. Find an element in the array
      1. Compare array elements together.
    2. Calculate the total array.
    3. All answers are wrong
  7. Question 7. What does the following program do?
     class ContinueDemo { 

    public static void main (String [] args) {

    String searchMe = 'peter piper picked up a peck of pickled peppers';

    int max = searchMe.length ();

    int numPs = 0;

    for (int i = 0; i
    if (searchMe.charAt (i)! = 'p') continue;

    numPs ++;

    }

    System.out.println ('Found' + numPs + 'p's in the string.');

    }

    }
    1. Count the letter p in the character string
    2. Find out if the p is in front of the letter i in the string
    3. Search for letter p in the string
    4. All is wrong
  8. Question 8. What is the result of the following program?
     class ContinueDemo { 

    public static void main (String [] args) {

    String searchMe = 'peter piper picked up a peck of pickled peppers';

    int max = searchMe.length ();

    int numPs = 0;

    for (int i = 0; i
    if (searchMe.charAt (i)! = 'p')

    tiếp tục;

    numPs ++;

    }

    System.out.println ('Found' + numPs + 'p's in the string.');

    }

    }
      1. Found 9 p's in the string.
    1. Found 8 p's in the string.
    2. Found 10 p's in the string.
    3. There is no right answer.
  9. Question 9. What is the result of the following program?
     class ContinueDemo { 

    public static void main (String [] args) {

    String searchMe = 'peter piper picked up a peck of pickled pepers';

    int max = searchMe.length ();

    int numPs = 0;

    for (int i = 0; i
    if (searchMe.charAt (i)! = 'p')

    tiếp tục;

    numPs ++;

    }

    System.out.println ('Found' + numPs + 'p's in the string.');

    }

    }
    1. Found 9 p's in the string.
    2. Found 8 p's in the string.
    3. Found 10 p's in the string.
    4. There is no right answer.
  10. Question 10. Which method of the String class returns the index of the child string that appears first in the char character string '
    1. concat ()
    2. charAt ()
    3. indexOf ()
    4. There is no right answer.
Update 24 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile