ログイン

IT232 مراجعة
56問 • 1ヶ月前
  • ユーザ名非公開
  • 通報

    問題一覧

  • 1

    1. How many times does the following for loop execute? for (i=0; i<=10; i++) System.out.println(i*i);

    11

  • 2

    2. Which of the following conditions is the correct condition for (int x) is a positive number and less than 100?

    if (x>0 && x<100)

  • 3

    3. In JAVA language primitive data type like, integer (int) reserves……memory, whereas Boolean reserves…….bytes.

    4,1

  • 4

    4. What is the output of following code? int arr1[] = new int[9]; System.out.println(arr1[9]);

    Error, because index out of boundary.

  • 5

    5. Instance variables belong to:

    an object

  • 6

    6. __________ contains instructions to initialize the instance variables of an object.

    Constructor

  • 7

    7. The nextLine() String method reads a line until the user hits:

    Enter.

  • 8

    8. Given the following code, which of the following cases causes the loop to stop? double total = 0; while (in.hasNextDouble()) { double input = in.nextDouble(); total = total + input; }

    When the user insert "Hello"

  • 9

    9. string1.compareTo(string2) < 0 means:

    string1 comes before string2 in the dictionary

  • 10

    10. A class with a ……………… method that contains statements to test another class is called a tester class.

    main

  • 11

    11. Which of the following results in an infinite loop?

    while (true)

  • 12

    12. What is the output of the code: int x = 0; for (i = 3; i > 0; i--); x++; System.out.println(x);

    1

  • 13

    13. What is the value of Math.sqrt(Math.pow(a, 9) + Math.pow(b, 4)) in mathematical notation?

    √a⁹ + b⁴

  • 14

    14. Which one of the following options is a valid line of code for displaying the 19th element of myarray?

    System.out.println(myarray[18]);

  • 15

    15. What is the valid range of index values for an array of size 10?

    0 to 9

  • 16

    16. What is the output of the following code snippet? int[] myarray = { 10, 20, 30, 40, 50 }; System.out.print(myarray[2]); System.out.print(myarray[3]);

    3040

  • 17

    17. Identify the correct statement for defining an integer array named numarray of ten elements.

    int[] numarray = new int[10];

  • 18

    18. Suppose you wish to write a method that returns the sum of the elements in the partially filled array myArray. Which is a reasonable method header?

    public static int sum(int[] values, int currSize)

  • 19

    19. In a partially filled array, the number of slots in the array that are not currently used is:

    the length of the array minus the number of elements currently in the array

  • 20

    20. What is the output of the given code snippet? int[] mynum = new int[5]; for (int i = 1; i < 5; i++) { mynum[i] = i + 1; System.out.print(mynum[i]); }

    2345

  • 21

    25 – What is the output of the following code snippet? int grade = 85; int finalGrade = 90; grade = finalGrade++; System.out.println(grade + " & " + finalGrade); a) 85 & 90 b) 90 & 91 c) 90 & 90 d) 91 & 91

    90 & 91

  • 22

    26 – You would use float and double to hold a) Whole Numbers b) Letters and Numbers c) Boolean and Numbers d) Real Numbers

    Real Numbers

  • 23

    27 – Java stores it's variable on a) Desktop b) Hard Drives c) Memory d) Class

    Memory

  • 24

    28 – First Class / Second Class 1 – What is the object-oriented programing concept presents in this code? class Person { String first_name; String last_Name; void printInf() { System.out.println("First Name is " + first_name + "last Name is " + last_Name); } } class Student extends Person { double GPA; String department; Student() { first_name = "Ahmed "; last_Name = " Alghamdi "; GPA = 4; department = "Computer Science"; } void printInf(){ super.printInf(); System.out.println(" GPA is "+ GPA + " department is " + department); } } public class FinalTester { public static void main(String[] args) { Person P = new Person(); Student s = new Student(); P.printInf(); s.printInf(); } }

    Class , Object, Inheritance, Override, and super keyword.

  • 25

    28 – First Class / Second Class 2 – Give the output of the program. class Person { String first_name; String last_Name; void printInf() { System.out.println("First Name is " + first_name + "last Name is " + last_Name); } } class Student extends Person { double GPA; String department; Student() { first_name = "Ahmed "; last_Name = " Alghamdi "; GPA = 4; department = "Computer Science"; } void printInf(){ super.printInf(); System.out.println(" GPA is "+ GPA + " department is " + department); } } public class FinalTester { public static void main(String[] args) { Person P = new Person(); Student s = new Student(); P.printInf(); s.printInf(); } }

    First Name is null last Name is null, First Name is Ahmed last Name is Alghamdi, GPA is 4.0 department is Computer Science

  • 26

    29 – Which of these is an incorrect array declaration? a) int[] arr = new int[4]; b) int arr[] = new int [4]; c) int arr[] = int [4] new; d) int arr[] = {1,2,3,4};

    int arr[] = int [4] new;

  • 27

    30 – When a recursive method is called to solve a problem, it's actually capable of solving only a) Unknown case(s) b) Complicated case c) Base case d) Similar Case

    Base case

  • 28

    31 – The method compareTo() in Java is used to compare a) One double with another double b) One String with another String c) On int with another int d) One float with another float

    One String with another String

  • 29

    32 – Which of the following Java process automates the removal of objects that are no longer required or active and returns memory to System? a) JVM collection b) JProfiler Collection c) Garbage Collection d) JConsole Collection

    Garbage Collection

  • 30

    33 – The ______ series has the characteristic that every succeeding number is the sum of the two before it. a) Overlapping b) Greedy c) Memoization d) Fibonacci

    Fibonacci

  • 31

    34 – What is the output of the following code snippet? System.out.println(Pattern.matches(".s", "as")); a) as b) true c) .s d) none of them

    true

  • 32

    35 – Java allows a class to have any number of constructors with different parameters. a) Constructor Overloading b) Compiler Overloading c) Garbage Collection d) Recursive Function

    Constructor Overloading

  • 33

    36 – When a Java application starts, what is the name of the method that is executed? a) start() b) class() c) main() d) begin()

    main()

  • 34

    37 – What is the output of the Following Java Code? int x = 4; String y = "Welcome"; System.out.printf("%d %S",x,y); a) Welcome b) x y c) 4 d) 4 WELCOME

    4 WELCOME

  • 35

    38 – Method overloading is implemented in Java by having several methods a) With different names b) In different packages c) With the same name d) In different classes

    With the same name

  • 36

    39 – What is the output of the following java code? char chars[] = {'a','b','c'}; System.out.println(chars[1]); a) b b) c c) a d) abc

    b

  • 37

    40 – Which of the following is NOT an object oriented programming concept in Java a) inheritance b) Polymorphism c) Compilation d) Composition

    Compilation

  • 38

    41 – How many times does the following code fragment display "Hi" int i = 4; while (i >= 0) { System.out.println("Hi"); i--; } a) 4 times b) 5 times c) 3 times d) 6 times

    5 times

  • 39

    42 – Which of these are selection statements in Java? a) continue b) break c) if() d) for()

    if()

  • 40

    43 – What is the output of the following Java statement? System.out.printf("\n The Number is %07d",1234); a) The Number is 0001234 b) The Number is 1234 c) The Number is 4321 d) The Numbers is 1234000

    The Number is 0001234

  • 41

    44 – What is the output of the following code snippet? int[] myArray = {11,12,13,14,15}; System.out.print(myArray[2]+","); System.out.print(myArray[3]); a) 14,15 b) 12,31 c) 15 d) 13,14

    13,14

  • 42

    45 – What is the extension of the compiled java classes? a) .class b) .java c) .js d) .txt

    .class

  • 43

    46 – Recursion Controls repetition by a) creating a complex case to be solved b) reducing 1 in each iteration c) dividing problem into simpler one d) adding 1 in each iteration

    dividing problem into simpler one

  • 44

    47 – What is the output of the following code snippet? String value = "Today is an exam day!"; System.out.println(value.substring(12)); a) empty space b) exam day! c) Today is an d) Today is an exam day!

    exam day!

  • 45

    48 – What is the output of the following java code? int array_variable [][] = {{1,2,3}, {4,5,6}, {7,8,9}}; System.out.println(array_variable[0][0]); a) 4 b) 2 c) 1 d) 7

    1

  • 46

    49 – Write the method named calculateArea (not a complete java program) to calculate and print the area of the Rectangle and Triangle based on the following formulas: Rectangle_area = height * width Traingle_area = height * width / 2 The method receives two float parameters height and width and has no return type. Given answer: static void calculateArea(double height, double width) { double Rectangle_area = height * width; double Triangle_aea = height * width / 2; System.out.println("Area of the Rectangle is : " + Rectangle_area); System.out.println("Area of the Triangle is : " + Triangle_aea); }

    static void calculateArea(double height, double width) { double Rectangle_area = height * width; double Triangle_aea = height * width / 2; System.out.println("Area of the Rectangle is : " + Rectangle_area); System.out.println("Area of the Triangle is : " + Triangle_aea); }

  • 47

    50 – Write a Java Program to calculate the sum and the average of an array. The program should: - Calculate the sum of all the items of the array using for loop - Print the sum - Divide the sum with the length of the array to get the average of numbers - Print the average. Given answer: public static void main(String[] args) { Scanner mySc = new Scanner(System.in); int[] a = new int[5]; int sum = 0; double average = 0; System.out.println("Enter all the elements"); for (int i = 0; i < 5; i++) { a[i] = mySc.nextInt(); } for (int i = 0; i < a.length; i++) { sum += a[i]; } average = sum / a.length; System.out.println("Sum : " + sum); System.out.println("the average : "+average); }

    public static void main(String[] args) { Scanner mySc = new Scanner(System.in); int[] a = new int[5]; int sum = 0; double average = 0; System.out.println("Enter all the elements"); for (int i = 0; i < 5; i++) { a[i] = mySc.nextInt(); } for (int i = 0; i < a.length; i++) { sum += a[i]; } average = sum / a.length; System.out.println("Sum : " + sum); System.out.println("the average : "+average); }

  • 48

    51 – What is the output of the following Java code? public static void main(String[] args) { String name1 = "FOX", name2 = "DOG"; if (name1 == "FOX") System.out.println("FOX"); System.out.println("Good"); if (name2 == "CAT") { System.out.println("DINO"); } }

    FOX, GOOD

  • 49

    52 – A variable which is created inside the class but outside the method is known as ______ variable. a) local b) private c) public d) instance

    instance

  • 50

    53 – In Java, which of the following is correct to import the entire package "my_pack" a) Import my_pack.*; b) Import my_pack.; c) import my_pack.; d) import my_pack.*;

    import my_pack.*;

  • 51

    54 – ______ variable gets memory only once in the class area at the time of class loading a) local b) static c) public d) private

    static

  • 52

    55 – Complete the following code snippet with correct enhanced for loop so it iterates the array. String[] fruit = {"apple","orange","banana"}; // enhanced loop System.out.println(e); } a) for (e: fruit[]) b) for (e: String fruit) c) for (e[] : fruit) d) for (String e: fruit)

    for (String e: fruit)

  • 53

    56 – Polymorphism in Java can be achieved by a) Final Class b) composition c) Static Method d) Method Overloading

    Method Overloading

  • 54

    57 – ______ variables that can be visible and accessible within the class they belong to and not outside the class or any other class a) public static b) private c) protected d) public

    private

  • 55

    58 – If you want to define class as child you use ? a) private b) public c) extends d) static

    extends

  • 56

    59 – The Output for the following code is. boolean value1 = false; System.out.print(value1); a) 0 b) value1 c) Syntax Error d) false

    false

  • 問題一覧

  • 1

    1. How many times does the following for loop execute? for (i=0; i<=10; i++) System.out.println(i*i);

    11

  • 2

    2. Which of the following conditions is the correct condition for (int x) is a positive number and less than 100?

    if (x>0 && x<100)

  • 3

    3. In JAVA language primitive data type like, integer (int) reserves……memory, whereas Boolean reserves…….bytes.

    4,1

  • 4

    4. What is the output of following code? int arr1[] = new int[9]; System.out.println(arr1[9]);

    Error, because index out of boundary.

  • 5

    5. Instance variables belong to:

    an object

  • 6

    6. __________ contains instructions to initialize the instance variables of an object.

    Constructor

  • 7

    7. The nextLine() String method reads a line until the user hits:

    Enter.

  • 8

    8. Given the following code, which of the following cases causes the loop to stop? double total = 0; while (in.hasNextDouble()) { double input = in.nextDouble(); total = total + input; }

    When the user insert "Hello"

  • 9

    9. string1.compareTo(string2) < 0 means:

    string1 comes before string2 in the dictionary

  • 10

    10. A class with a ……………… method that contains statements to test another class is called a tester class.

    main

  • 11

    11. Which of the following results in an infinite loop?

    while (true)

  • 12

    12. What is the output of the code: int x = 0; for (i = 3; i > 0; i--); x++; System.out.println(x);

    1

  • 13

    13. What is the value of Math.sqrt(Math.pow(a, 9) + Math.pow(b, 4)) in mathematical notation?

    √a⁹ + b⁴

  • 14

    14. Which one of the following options is a valid line of code for displaying the 19th element of myarray?

    System.out.println(myarray[18]);

  • 15

    15. What is the valid range of index values for an array of size 10?

    0 to 9

  • 16

    16. What is the output of the following code snippet? int[] myarray = { 10, 20, 30, 40, 50 }; System.out.print(myarray[2]); System.out.print(myarray[3]);

    3040

  • 17

    17. Identify the correct statement for defining an integer array named numarray of ten elements.

    int[] numarray = new int[10];

  • 18

    18. Suppose you wish to write a method that returns the sum of the elements in the partially filled array myArray. Which is a reasonable method header?

    public static int sum(int[] values, int currSize)

  • 19

    19. In a partially filled array, the number of slots in the array that are not currently used is:

    the length of the array minus the number of elements currently in the array

  • 20

    20. What is the output of the given code snippet? int[] mynum = new int[5]; for (int i = 1; i < 5; i++) { mynum[i] = i + 1; System.out.print(mynum[i]); }

    2345

  • 21

    25 – What is the output of the following code snippet? int grade = 85; int finalGrade = 90; grade = finalGrade++; System.out.println(grade + " & " + finalGrade); a) 85 & 90 b) 90 & 91 c) 90 & 90 d) 91 & 91

    90 & 91

  • 22

    26 – You would use float and double to hold a) Whole Numbers b) Letters and Numbers c) Boolean and Numbers d) Real Numbers

    Real Numbers

  • 23

    27 – Java stores it's variable on a) Desktop b) Hard Drives c) Memory d) Class

    Memory

  • 24

    28 – First Class / Second Class 1 – What is the object-oriented programing concept presents in this code? class Person { String first_name; String last_Name; void printInf() { System.out.println("First Name is " + first_name + "last Name is " + last_Name); } } class Student extends Person { double GPA; String department; Student() { first_name = "Ahmed "; last_Name = " Alghamdi "; GPA = 4; department = "Computer Science"; } void printInf(){ super.printInf(); System.out.println(" GPA is "+ GPA + " department is " + department); } } public class FinalTester { public static void main(String[] args) { Person P = new Person(); Student s = new Student(); P.printInf(); s.printInf(); } }

    Class , Object, Inheritance, Override, and super keyword.

  • 25

    28 – First Class / Second Class 2 – Give the output of the program. class Person { String first_name; String last_Name; void printInf() { System.out.println("First Name is " + first_name + "last Name is " + last_Name); } } class Student extends Person { double GPA; String department; Student() { first_name = "Ahmed "; last_Name = " Alghamdi "; GPA = 4; department = "Computer Science"; } void printInf(){ super.printInf(); System.out.println(" GPA is "+ GPA + " department is " + department); } } public class FinalTester { public static void main(String[] args) { Person P = new Person(); Student s = new Student(); P.printInf(); s.printInf(); } }

    First Name is null last Name is null, First Name is Ahmed last Name is Alghamdi, GPA is 4.0 department is Computer Science

  • 26

    29 – Which of these is an incorrect array declaration? a) int[] arr = new int[4]; b) int arr[] = new int [4]; c) int arr[] = int [4] new; d) int arr[] = {1,2,3,4};

    int arr[] = int [4] new;

  • 27

    30 – When a recursive method is called to solve a problem, it's actually capable of solving only a) Unknown case(s) b) Complicated case c) Base case d) Similar Case

    Base case

  • 28

    31 – The method compareTo() in Java is used to compare a) One double with another double b) One String with another String c) On int with another int d) One float with another float

    One String with another String

  • 29

    32 – Which of the following Java process automates the removal of objects that are no longer required or active and returns memory to System? a) JVM collection b) JProfiler Collection c) Garbage Collection d) JConsole Collection

    Garbage Collection

  • 30

    33 – The ______ series has the characteristic that every succeeding number is the sum of the two before it. a) Overlapping b) Greedy c) Memoization d) Fibonacci

    Fibonacci

  • 31

    34 – What is the output of the following code snippet? System.out.println(Pattern.matches(".s", "as")); a) as b) true c) .s d) none of them

    true

  • 32

    35 – Java allows a class to have any number of constructors with different parameters. a) Constructor Overloading b) Compiler Overloading c) Garbage Collection d) Recursive Function

    Constructor Overloading

  • 33

    36 – When a Java application starts, what is the name of the method that is executed? a) start() b) class() c) main() d) begin()

    main()

  • 34

    37 – What is the output of the Following Java Code? int x = 4; String y = "Welcome"; System.out.printf("%d %S",x,y); a) Welcome b) x y c) 4 d) 4 WELCOME

    4 WELCOME

  • 35

    38 – Method overloading is implemented in Java by having several methods a) With different names b) In different packages c) With the same name d) In different classes

    With the same name

  • 36

    39 – What is the output of the following java code? char chars[] = {'a','b','c'}; System.out.println(chars[1]); a) b b) c c) a d) abc

    b

  • 37

    40 – Which of the following is NOT an object oriented programming concept in Java a) inheritance b) Polymorphism c) Compilation d) Composition

    Compilation

  • 38

    41 – How many times does the following code fragment display "Hi" int i = 4; while (i >= 0) { System.out.println("Hi"); i--; } a) 4 times b) 5 times c) 3 times d) 6 times

    5 times

  • 39

    42 – Which of these are selection statements in Java? a) continue b) break c) if() d) for()

    if()

  • 40

    43 – What is the output of the following Java statement? System.out.printf("\n The Number is %07d",1234); a) The Number is 0001234 b) The Number is 1234 c) The Number is 4321 d) The Numbers is 1234000

    The Number is 0001234

  • 41

    44 – What is the output of the following code snippet? int[] myArray = {11,12,13,14,15}; System.out.print(myArray[2]+","); System.out.print(myArray[3]); a) 14,15 b) 12,31 c) 15 d) 13,14

    13,14

  • 42

    45 – What is the extension of the compiled java classes? a) .class b) .java c) .js d) .txt

    .class

  • 43

    46 – Recursion Controls repetition by a) creating a complex case to be solved b) reducing 1 in each iteration c) dividing problem into simpler one d) adding 1 in each iteration

    dividing problem into simpler one

  • 44

    47 – What is the output of the following code snippet? String value = "Today is an exam day!"; System.out.println(value.substring(12)); a) empty space b) exam day! c) Today is an d) Today is an exam day!

    exam day!

  • 45

    48 – What is the output of the following java code? int array_variable [][] = {{1,2,3}, {4,5,6}, {7,8,9}}; System.out.println(array_variable[0][0]); a) 4 b) 2 c) 1 d) 7

    1

  • 46

    49 – Write the method named calculateArea (not a complete java program) to calculate and print the area of the Rectangle and Triangle based on the following formulas: Rectangle_area = height * width Traingle_area = height * width / 2 The method receives two float parameters height and width and has no return type. Given answer: static void calculateArea(double height, double width) { double Rectangle_area = height * width; double Triangle_aea = height * width / 2; System.out.println("Area of the Rectangle is : " + Rectangle_area); System.out.println("Area of the Triangle is : " + Triangle_aea); }

    static void calculateArea(double height, double width) { double Rectangle_area = height * width; double Triangle_aea = height * width / 2; System.out.println("Area of the Rectangle is : " + Rectangle_area); System.out.println("Area of the Triangle is : " + Triangle_aea); }

  • 47

    50 – Write a Java Program to calculate the sum and the average of an array. The program should: - Calculate the sum of all the items of the array using for loop - Print the sum - Divide the sum with the length of the array to get the average of numbers - Print the average. Given answer: public static void main(String[] args) { Scanner mySc = new Scanner(System.in); int[] a = new int[5]; int sum = 0; double average = 0; System.out.println("Enter all the elements"); for (int i = 0; i < 5; i++) { a[i] = mySc.nextInt(); } for (int i = 0; i < a.length; i++) { sum += a[i]; } average = sum / a.length; System.out.println("Sum : " + sum); System.out.println("the average : "+average); }

    public static void main(String[] args) { Scanner mySc = new Scanner(System.in); int[] a = new int[5]; int sum = 0; double average = 0; System.out.println("Enter all the elements"); for (int i = 0; i < 5; i++) { a[i] = mySc.nextInt(); } for (int i = 0; i < a.length; i++) { sum += a[i]; } average = sum / a.length; System.out.println("Sum : " + sum); System.out.println("the average : "+average); }

  • 48

    51 – What is the output of the following Java code? public static void main(String[] args) { String name1 = "FOX", name2 = "DOG"; if (name1 == "FOX") System.out.println("FOX"); System.out.println("Good"); if (name2 == "CAT") { System.out.println("DINO"); } }

    FOX, GOOD

  • 49

    52 – A variable which is created inside the class but outside the method is known as ______ variable. a) local b) private c) public d) instance

    instance

  • 50

    53 – In Java, which of the following is correct to import the entire package "my_pack" a) Import my_pack.*; b) Import my_pack.; c) import my_pack.; d) import my_pack.*;

    import my_pack.*;

  • 51

    54 – ______ variable gets memory only once in the class area at the time of class loading a) local b) static c) public d) private

    static

  • 52

    55 – Complete the following code snippet with correct enhanced for loop so it iterates the array. String[] fruit = {"apple","orange","banana"}; // enhanced loop System.out.println(e); } a) for (e: fruit[]) b) for (e: String fruit) c) for (e[] : fruit) d) for (String e: fruit)

    for (String e: fruit)

  • 53

    56 – Polymorphism in Java can be achieved by a) Final Class b) composition c) Static Method d) Method Overloading

    Method Overloading

  • 54

    57 – ______ variables that can be visible and accessible within the class they belong to and not outside the class or any other class a) public static b) private c) protected d) public

    private

  • 55

    58 – If you want to define class as child you use ? a) private b) public c) extends d) static

    extends

  • 56

    59 – The Output for the following code is. boolean value1 = false; System.out.print(value1); a) 0 b) value1 c) Syntax Error d) false

    false