Deck 2: Data and Expressions
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
العب
ملء الشاشة (f)
Deck 2: Data and Expressions
1
Which of the following data types only allows one of two possible values to be assigned?
A) char
B) int
C) boolean
D) float
E) long
A) char
B) int
C) boolean
D) float
E) long
C
Explanation: Variables of type boolean can only be assigned values of true or false. The other four types can be assigned many different values.
Explanation: Variables of type boolean can only be assigned values of true or false. The other four types can be assigned many different values.
2
Which of the following lines allows a programmer to use the Scanner class in a Java program?
A) import java.util.Scanner;
B) using Scanner;
C) include Scanner;
D) include java.util.Scanner;
E) any of the above will allow the programmer to use the Scanner class
A) import java.util.Scanner;
B) using Scanner;
C) include Scanner;
D) include java.util.Scanner;
E) any of the above will allow the programmer to use the Scanner class
A
Explanation: The Scanner class must be imported using the import command before it may be used in a program.
Explanation: The Scanner class must be imported using the import command before it may be used in a program.
3
The byte type can be assigned a larger range of numbers than the int type.
False
Explanation: The int type can hold numbers in the range -2,147,483 to 2,147,483,647 while the byte type can only hold numbers in the range -128 to 127.
Explanation: The int type can hold numbers in the range -2,147,483 to 2,147,483,647 while the byte type can only hold numbers in the range -128 to 127.
4
Which of the following is an example of an invalid expression in Java?
A) result = a + b;
B) result = (14 + 9) * 5;
C) result = ((19 + 4) - 5;
D) result = firstNum % secondNum;
E) result = firstNum / secondNum % thirdNum;
A) result = a + b;
B) result = (14 + 9) * 5;
C) result = ((19 + 4) - 5;
D) result = firstNum % secondNum;
E) result = firstNum / secondNum % thirdNum;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
Consider the following snippet of code: int firstNum = 25;
Int seconNum = 3;
Double result = 25/3;
System.out.println(result);
What is output by this code?
A) 8.0
B) 8.333333333
C) 8
D) 8.3
E) This snippet of code will result in a compiler error
Int seconNum = 3;
Double result = 25/3;
System.out.println(result);
What is output by this code?
A) 8.0
B) 8.333333333
C) 8
D) 8.3
E) This snippet of code will result in a compiler error
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
Java has two basic kinds of numeric values: _____________, which have no fractional part, and ___________________ which do.
A) shorts, longs
B) doubles, floating points
C) characters, bytes
D) integers, floating points
E) integers, longs
A) shorts, longs
B) doubles, floating points
C) characters, bytes
D) integers, floating points
E) integers, longs
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
In order to make a variable a constant which modifier must be included in its declaration?
A) public
B) final
C) static
D) void
E) private
A) public
B) final
C) static
D) void
E) private
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
In order for a string literal may span multiple lines in the program code.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
Information is most likely to be lost in what kind of data conversion?
A) A widening conversion
B) A narrowing conversion
C) promotion
D) assignment conversion
E) no information will be lost in any of the conversions listed above
A) A widening conversion
B) A narrowing conversion
C) promotion
D) assignment conversion
E) no information will be lost in any of the conversions listed above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following is not an arithmetic operation in Java?
A) +
B) -
C) *
D) %
E) These are all arithmetic operations in Java
A) +
B) -
C) *
D) %
E) These are all arithmetic operations in Java
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following are examples of invalid string literals?
A) "Hello World!"
B) "4 score and 7 years ago, our forefathers brought forth..."
C) "z"
D) ""
E) none of the above
A) "Hello World!"
B) "4 score and 7 years ago, our forefathers brought forth..."
C) "z"
D) ""
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
Variables declared with the final modifier cannot have new values assigned to them.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
A(n) ________________ is a piece of data that we send to a method.
A) parameter
B) object
C) escape sequence
D) service
E) expression
A) parameter
B) object
C) escape sequence
D) service
E) expression
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
Java is a strongly-typed language.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
Consider the following snippet of code: System.out.println("30 plus 25 is " + 30 + 25);
What is printed by this line?
A) 30 plus 25 is 55
B) 30 plus 25 is 30
C) 30 plus 25 is 25
D) 30 plus 25 is 3025
E) this snippet of code will result in a compiler error
What is printed by this line?
A) 30 plus 25 is 55
B) 30 plus 25 is 30
C) 30 plus 25 is 25
D) 30 plus 25 is 3025
E) this snippet of code will result in a compiler error
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which of the following is an example of an invalid assignment or declaration statement?
A) int age = 30;
B) int money, dollars = 0, cents = 0;
C) int years = 1; months = 12; days = 365;
D) int length, meters, centimeters, millimeters;
E) none of the above
A) int age = 30;
B) int money, dollars = 0, cents = 0;
C) int years = 1; months = 12; days = 365;
D) int length, meters, centimeters, millimeters;
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
Consider the expression: result = 12 + 5 / 2;
What value stored in result after this line is executed?
A) 14.5
B) 8.5
C) 9
D) 14
E) this will result in a compiler error
What value stored in result after this line is executed?
A) 14.5
B) 8.5
C) 9
D) 14
E) this will result in a compiler error
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
Consider the expression: result = 15 % 4;
What value stored in result after this line is executed?
A) 0
B) 1
C) 2
D) 3
E) 4
What value stored in result after this line is executed?
A) 0
B) 1
C) 2
D) 3
E) 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
A _______________ is a list of characters in a particular order. Examples include ASCII and Unicode.
A) character literal
B) character set
C) char data type
D) control character
E) none of the above
A) character literal
B) character set
C) char data type
D) control character
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
The print and the println methods are identical and can be used interchangeably.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
Write a single println statement that prints out the following line.
"There is Thingumbob shouting!" the Bellman said,
"There is Thingumbob shouting!" the Bellman said,
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
The type of result produced by a mathematical expression depends on the types of the operands.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
Write a short program that allows the user to enter the year that they were born (as an integer) and outputs the age that they will be at the end of this year. Declare the current year as a constant.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
What are some reasons that you might want to declare a variable as final?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
Consider the following snippet of code:
int firstNum = 5;
int secondNum = firstNum++;
int thirdNum = 6*(++firstNum);
What values are stored in firstNum, secondNum and thirdNum after these lines are executed? Explain your answer.
int firstNum = 5;
int secondNum = firstNum++;
int thirdNum = 6*(++firstNum);
What values are stored in firstNum, secondNum and thirdNum after these lines are executed? Explain your answer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
Promotion is a widening data conversion that is explicitly requested by the programmer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
Java uses the ASCII character set to represent character data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
The Scanner class must be imported using the import statement before it can be used in a program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Explain why it might not be safe for a programmer to use a narrowing conversion.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
Write a short application that converts inches to centimeters. It should read the number of inches from the user as a floating point number and output the number of inches and the number of centimeters at the end of the program. Note that there are 2.54 centimeters in an inch.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
Write a single line of Java code that computes the average of three integer variables - num1, num2, and num3 - and stores the result in a variable of type double called result.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
Write an application that prints out the following using a single call to the print method.
Hello!
How
are you?
Hello!
How
are you?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
Write a short application that computes the perimeter of a rectangle. It should allow the user to input the length and width of the rectangle as a double.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
Write a short program that declares a single integer variable called age and assigns it a value equal to your age. Also have it print out your age using the age variable. The output of your program should look similar to the following:
I am 30 years old.
I am 30 years old.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
Consider the following snippet of code.
int iResult;
float fResult;
int rResult;
int iNum1 = 25;
int iNum2 = 8;
iResult = iNum1/iNum2;
rResult = iNum2%iNum2;
fResult = (float) iNum1/iNum2;
What values are stored in iResult, rResult and fResult? Explain your answers.
int iResult;
float fResult;
int rResult;
int iNum1 = 25;
int iNum2 = 8;
iResult = iNum1/iNum2;
rResult = iNum2%iNum2;
fResult = (float) iNum1/iNum2;
What values are stored in iResult, rResult and fResult? Explain your answers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
For the following expression, indicate the order that in which the operators will be evaluated.
a + b * c / (d -
e)
a + b * c / (d -
e)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
In Java, all floating point literals are assumed to be of type float.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
How are primitive data types and object data types related?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
Explain the difference between the print and the println methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
Suppose your numeric grade is calculated using the following formula:
Test 1: 15%
Test 2: 15%
Final Exam: 30%
Homework: 10%
Programming Projects: 30%
Determine a good variable name to represent each of these values. Write a single expression to compute your grade assuming the variables have been declared and each one stores its value as an integer in the range 0 to 100.
Test 1: 15%
Test 2: 15%
Final Exam: 30%
Homework: 10%
Programming Projects: 30%
Determine a good variable name to represent each of these values. Write a single expression to compute your grade assuming the variables have been declared and each one stores its value as an integer in the range 0 to 100.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck