Test Preparation - Informatics

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the output produced by the following segment of code? (2 points) int x = 2; if (x >= 0) {y=20% (x+3) + 3; System.out.print(y);} else {y= 2*x - (x+1); System.out.print(y);}

3

Which operator is used to multiply numbers? (1 p.) * # % x

a)

Which statement is true for the defined array: (2 points) double [] values = {54, 67.5, 115, 44.7, 100, 65}; a) The defined array has a name: double. b) The defined array has an index: values. c) The defined array has eight values. d) The defined array has six elements.

d)

What is the output produced by the following segment of code? (2 points) int x = 7; int y = 2; int z = x %y - 1 ;

0

What is the output produced by the following segment of code? (2 points) int x = 9; int y = 2; int z = x % y - 1 ;

0

What is the output produced by the following segment of code? (2 points) for (int i = 0; i < 9; i++) System.out.print("*"); Choices: a) ****** b) ********** c) * d) An infinite sequence of asterisks is generated.

b)

What is the output produced by the following segment of code? (2 points) public class Main{ public static void main(String[] args) { int [] arr = { -52, 6, -4, 0, 3, 12 }; int min=arr[0]; for(int i=1;i<arr.length;i++) if(arr[i]<min) min=arr[i]; System.out.println("min="+ min); } }

-52

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int a = 3; int b = 3; double S; if (a!= 0 && b!=0) {S=(a+b)/3; System.out.print(S);} else { System.out.println("incorrect data.");}} }

0.0

What is the output produced by the following segment of code? (2 points) int x = 2; if (x >= 0) {y=20% (x+2) + 1; System.out.print(y);} else {y= 3*x + (x - 2); System.out.print(y);}

1

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int sum=0; int i=1; for ( i=1 ; i <= 5; i++ ){sum = sum + i;} System.out.println("sum="+sum); } } Output: 15.

1 + 2 + 3 + 4 + 5 = 15

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int sum =0; int i=2; while(i<=6) {sum = sum + i; i = i + 2;} System.out.println("sum="+ sum); } }

12

What is the output produced by the following segment of code? (2 points) public class Main{ public static void main(String[] args) { int product=1; for( int i=1 ; i <=10; i=i+3 ){product =product * i;} System.out.println("product=" + product); } }

280

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int [] arr = { 4, 6, -4, 20, 33, 45 }; int max=arr[0]; for(int i=1;i<arr.length;i++) if(max<arr[i]) max=arr[i]; System.out.println("max="+ max); } }

45

public class Main { public static void main(String[] args) { int [] arr = { 1, 2, 6, 3, 4, 5 }; int product = 1; for(int i=0;i<arr.length;i++){ if(arr[i]%2==0 && arr[i]!= 0) product=product*arr[i]; } System.out.println("product="+ product);

48

What is the output produced by the following segment of code? (2 points) int x = 5; int z = 2 * x - x%3;

8

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int [] arr = { 1, 2, 6, 3, 4, 5 }; int sum = 0; for(int i=0;i<arr.length;i++){ if(arr[i]%2!=0 && arr[i]!= 0) sum=sum+arr[i]; } System.out.println("sum="+ sum);

9

public class Main{ public static void main(String[] args){ int sum_even=0; int counter_even=0; for(int i=0;i<alfa.length;i++) if(alfa[i]%2==0) {sum_even=sum_even+alfa[i]; counter_even++ ; } System.out.println ("sum_even = " + sum_even); System.out.println ("counter_even = " + counter_even); } }

Output: sum of the even numbers and their counter

Choose the appropriate data type for this value: 5.50 (1 p.) double boolean string int

a)

How do you insert COMMENTS in Java code? (1 p.) a) // This is a comment b) # This is a comment c) /* This is a comment

a)

How do you start writing a while loop in Java? (1 p.) while (x < y) x < y while { while x < y { while x < y:

a)

How do you start writing a while loop in Java? (1 p.) while (x > y) x > y while { while x > y { while x > y:

a)

How do you start writing an if statement in Java? (1 p.) if (x < y) if x < y: if x < y then:

a)

How do you start writing an if statement in Java? (1 p.) if (x > y) if x > y: if x > y then:

a)

The statement S -= i; is equivalent to: (2 points) Choices: a) S = S - i; b) S = i - 1; c) i = S - i; d) i = S - 1;

a)

The statement S /= i; is equivalent to: (2 points) Choices: a) S = S / i; b) S = i *1; c) i = S % i; d) i = S /1;

a)

What is the output produced by the following segment of code? (2 points) for (int i = 0; i < 4; i++) System.out.print("*"); Choices: a) **** b) ********** c) * d) An infinite sequence of asterisks is generated.

a)

What is the output produced by the following segment of code? (2 points) for(int i=5; i>=1; i--) System.out.print(i); Choices: a) 54321 b) 12345c) There is no output generated. d) An error message is generated.

a)

What is the output produced by the following segment of code? (2 points) for(int i=7; i>=2; i--) System.out.print(i); Choices: a) 765432 b) 234567c) There is no output generated. d) An error message is generated.

a)

What is the output produced by the following segment of code? (2 points) int a = 2; int b = 3; String incorrect = "Sum=" + a + b; System.out.println (incorrect); Choose the correct answer: Sum=23 Sum=23.0 Sum=2 Sum=23.0

a)

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int i=1; do{ System.out.println(i); i=i+1; } while(i<=3); } } Choices: a) 1 2 3 b)123 c)321 d) 3 2 1

a)

What is the output produced by the following segment of code? (2 points) public class Main { public static void main(String[] args) { int i=3; while(i<=5){ System.out.println(i); i=i+1; } } } Choices: a) 3 4 5 b)543 c)345 d) 5 4 3

a)

Which operator can be used to compare two values? (1 p.) a) == b) >< c) = d) <>

a)

Which statement is used to stop a loop? (1 p.) break return stop exit

a)

Array indexes start with: (1 p.) 1 0

b)

What is the output produced by the following segment of code? (2 points) int i; for( i=7; i>=3; i--) { System.out.print(i); } Choices: a) 34567 b) 76543 c) There is no output generated. d) An error message is generated.

b)

What is the output produced by the following segment of code? (2 points) int x = 12; int y = 10; System.out.println( x/y ); Choose the correct answer: 2 1 1.2 1.0

b)

What will be the values of the elements of the array after the execution of the following fragment of the program? (2 т.) int [] primes = {2, 3, 5, 7, 11}; for (int i = 0; i < 5; i++) { primes [i] ++; } a) 2, 3, 5, 7, 11 b) 3, 4, 6, 8, 11 c) 3, 4, 6, 8, 12 d) 4, 6, 10, 14, 12

b)

Array indexes start with: (1 p.) 2 1 0 3

c)

If you want your condition to depend upon two conditions BOTH being true, what is the proper notation to put between the two Boolean statements? (1 p.) ! || && ==

c)

The major difference between a while loop and a do-while loop is: (2 points) Choices: a) the while loop can execute the body of its loop more times. b) the while loop always executes its loop body at least once. c) the do-while loop always executes its loop body at least once. d) none; they are identical in all situations.

c)

To declare an array in Java, define the variable type with: (1 p.) () {} [] //

c)

Choose the appropriate data type for this value: 6 (1 p.) double boolean string int

d)

How do you create a variable with the numeric value 5? (1 p.) float x = 5; x = 5; num x = 5 int x = 5;

d)

How do you create a variable with the numeric value 7? (1 p.) float x = 7; x = 7; num x = 7 int x = 7;

d)

If you want your condition to depend upon two conditions BOTH being true, what is the proper notation to put between the two Boolean statements? (1 p.) ! || != &&

d)

Which operator is used to multiply numbers? (1 p.) x # % *

d)


Ensembles d'études connexes

Equations and Angle Relationships

View Set

Environmental Ethics Test #2 Study Guide

View Set

Primerica Life Insurance Practice Questions (w/out multiple choice)

View Set