Deck 2: Data and Expressions

ملء الشاشة (f)
exit full mode
سؤال
If x is an int and y is a float, all of the following are legal except which assignment statement?

A) y = x;
B) x = y;
C) y = (float) x;
D) x = (int) y;
E) all of the above are legal
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Which of the following is True regarding the mod operator, %?

A) It can only be performed on int values and its result is a double
B) It can only be performed on int values and its result is an int
C) It can only be performed on float or double values and its result is an int
D) It can only be performed on float or double values and its result is a double
E) It can be performed on any numeric values, and the result always is numeric
سؤال
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
A reasonable documentation comment for this program might be

A) // a program that demonstrates the differences between print, println and how + works
B) // a program that outputs a message about Texas
C) // a program that demonstrates nothing at all
D) // a program that outputs the message "Here There Everywhere But not in Texas"
E) // a program that contains three output statements
سؤال
The word println is a(n)

A) method
B) reserved word
C) variable
D) class
E) String
سؤال
Given the following assignment statement, which of the following answers is True regarding the order that the operators will be applied based on operator precedence?
A = (b + c) * d / e - f;

A) *, /, +, -
B) *, +, /, -
C) +, *, /, -
D) +, /, *, -
E) +, -, *, /
سؤال
What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
سؤال
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
The program will print the word "Here" and then print

A) "There Everywhere" on the line after "Here"
B) "There" on the line after "Here" and "Everywhere" on the line after "There"
C) "There Everywhere" on the same line as "Here"
D) "ThereEverywhere" on the same line as "Here"
E) "ThereEverywhere" on the line after "Here"
سؤال
If you want to output the text "hi there", including the quote marks, which of the following could do that?

A) System.out.println("hi there");
B) System.out.println(""hi there"");
C) System.out.println("\"hi there");
D) System.out.println("\"hi there\"");
E) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output
سؤال
A Java variable is the name of a

A) numeric data value stored in memory
B) data value stored in memory that can not change during the program's execution
C) data value stored in memory that can change its value but cannot change its type during the program's execution
D) data value stored in memory that can change both its value and its type during the program's execution
E) data value or a class stored in memory that can change both its value and its type during the program's execution
سؤال
Assume that x, y, and z are all integers (int) equal to 50, 20, and 6 respectively. What is the result of x / y / z?

A) 0
B) 12
C) 16
D) A syntax error as this is syntactically invalid
E) A run-time error because this is a division by 0
سؤال
A cast is required in which of the following situations?

A) using charAt to take an element of a String and store it in a char
B) storing an int in a float
C) storing a float in a double
D) storing a float in an int
E) all of the above require casts
سؤال
Of the following types, which one cannot store a numeric value?

A) int
B) byte
C) float
D) char
E) all of these can store numeric values
سؤال
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
How many lines of output are provided by this program?

A) 1
B) 2
C) 3
D) 4
E) 5
سؤال
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
The final println command will output

A) "But not in Texas"
B) "But notin Texas"
C) "But not" on one line and "in Texas" on the next line
D) "But not+in Texas"
E) "But not + in Texas"
سؤال
If you want to store into the String name the value "George Bush", you would do which statement?

A) String name = "George Bush";
B) String name = new String("George Bush");
C) String name = "George" + " " + "Bush";
D) String name = new String("George" + " " + "Bush");
E) Any of the above would work
سؤال
What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
سؤال
What will be the result of the following assignment statement? Assume b = 5 and c = 10.
Int a = b * (-c + 2) / 2;

A) 30
B) -30
C) 20
D) -20
E) -6
سؤال
What value will z have if we execute the following assignment statement?
Float z = 5 / 10;

A) z will equal 0.0
B) z will equal 0.5
C) z will equal 5.0
D) z will equal 0.05
E) none of the above, a run-time error arises because z is a float and 5 / 10 is an int
سؤال
Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ________ lines of text

A) 1
B) 2
C) 3
D) 4
E) 5
سؤال
Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying

A) c = a.length( ) + b.length( );
B) c = (int) a + (int) b;
C) c = a.concat(b);
D) c = b.concat(a);
E) c = a.plus(b);
سؤال
Assume that x is a double that stores 0.362491. To output this value as 36%, you could use the NumberFormat class with NumberFormat nf = NumberFormat.getPercentInstance( ); Which of the following statements then would output x as 36%?

A) System.out.println(x);
B) System.out.println(nf);
C) System.out.println(nf.x);
D) System.out.println(nf.format(x));
E) System.out.println(format(x));
سؤال
Which library package would you import to use the class Random?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
سؤال
Which of the following would return the last character of the String x?

A) x.charAt(0);
B) x.charAt(last);
C) x.charAt(length(x));
D) x.charAt(x.length( )-1);
E) x.charAt(x.length( ));
سؤال
For the following questions, refer to the class defined below:
import java.util.Scanner;
public class Questions
{
public static void main(String[ ] args)
{
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x = scan.nextInt( );
System.out.println("Enter another integer value");
y = scan.nextInt( );
System.out.println("Enter a third integer value");
z = scan.nextInt( );
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
What is output if x = 0, y = 1 and z = 1?

A) 0
B) 0.0
C) 0.6666666666666666
D) 0.6666666666666667
E) 0.67
سؤال
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The figure drawn in this applet is

A) a blue square
B) a blue square with two white lines drawn horizontally through it
C) a blue square with two white lines drawn diagonally through it
D) a blue square with two white lines drawn vertically through it
E) a white square with two blue lines drawn vertically through it
سؤال
For the following questions, refer to the class defined below:
import java.util.Scanner;
public class Questions
{
public static void main(String[ ] args)
{
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x = scan.nextInt( );
System.out.println("Enter another integer value");
y = scan.nextInt( );
System.out.println("Enter a third integer value");
z = scan.nextInt( );
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
Questions33_34 computes

A) The correct average of x, y and z as a double
B) The correct average of x, y and z as an int
C) The average of x, y, and z as a double, but the result may not be accurate
D) the sum of x, y and z
E) the remainder of the sum of x, y and z divided by 3
سؤال
Consider the double value likelihood = 0.013885. What would be output if DecimalFormat dformatter = DecimalFormat("0.00##"); and you execute System.out.println(df.format(likelihood)); ?

A) 0.013885
B) 0.0139
C) 0.014
D) )0139
E) )014
سؤال
In order to create a constant, you would use which of the following Java reserved words?

A) private
B) static
C) int
D) final
E) class
سؤال
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The String "A nice box" is drawn

A) above the box
B) to the left of the box
C) to the right of the box
D) below the box
E) inside the box
سؤال
You specify the shape of an oval in a Java applet by defining the oval's

A) arc locations
B) center and radius
C) bounding box
D) foci
E) none of the above, it is not possible to draw an oval in a Java applet
سؤال
What value will z have if we execute the following assignment statement?
Int z = 50 / 10.00;

A) 5
B) 5.0
C) 50
D) 10
E) none of the above, a run-time error arises because z is an int and 50 / 10.00 is not
سؤال
Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?

A) Math.sqrt(x*x);
B) Math.sqrt((int) x);
C) Math.sqrt(Math.abs(x));
D) Math.abs(Math.sqrt(x));
E) Math.sqrt(-x);
سؤال
Which library package would you import to use NumberFormat and DecimalFormat?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
سؤال
If you want to output a double so that at least 1 digit appears to the left side of the decimal point and exactly 1 digit appears to the right side of the decimal point, which pattern would you give a DecimalFormat variable when you instantiate it?

A) "0.0"
B) "0.#"
C) "0.0#"
D) "0.##"
E) "#.#"
سؤال
Suppose that String name = "Frank Zappa". What will the instruction name.toUpperCase( ).replace('A', 'I'); return?

A) "FRANK ZAPPA "
B) "FRINK ZIPPI"
C) "Frink Zippi"
D) "Frank Zappa"
E) "FrInk ZIppI"
سؤال
If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following sets of commands might you use?

A) page.setColor(Color.green); page.fillRect(50, 50, 100, 100);
Page.setColor(Color.red);
Page.fillOval(60, 60, 80, 80);
B) page.setColor(Color.red); page.fillOval(60, 60, 80, 80);
Page.setColor(Color.green);
Page.fillRect(50, 50, 100, 100);
C) page.setColor(Color.green); page.fillRect(60, 60, 80, 80);
Page.setColor(Color.red);
Page.fillOval(50, 50, 100, 100);
D) page.setColor(Color.red); page.fillOval(50, 50, 100, 100);
Page.setColor(Color.green);
Page.fillRect(60, 60, 80, 80);
E) any of the above would accomplish this
سؤال
Using getCurrencyInstance( ) formats a variable, automatically inserting

A) decimal point for cents
B) dollar sign
C) percent sign
D) all three
E) A and B but not C
سؤال
If the String major = "Computer Science", what is returned by major.charAt(1)?

A) 'C'
B) 'o'
C) 'm'
D) "C"
E) "Computer"
سؤال
If a, b, and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to

A) 0
B) 4
C) 5
D) -5
E) 23
سؤال
The Random class has a method nextFloat( ) which returns a random float value between

A) -1 and +1
B) 0 and 1
C) 0 and 99
D) 1 and 100
E) -2,147,483,648 and +2,147,483,647
سؤال
Many Java drawing shapes are specified using a bounding rectangle.
سؤال
In order to generate a random number, you must use Math.random( ).
سؤال
In Java, 'a' and 'A' are considered to be different values.
سؤال
Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a float value and input it using the Scanner class into the variable y.
سؤال
There are three ways that data conversion may occurby assignment, by promotion, by casting.
سؤال
If x is a string, then x = new String("OH"); and x = "OH"; will accomplish the same thing.
سؤال
Java is a strongly typed language. What is meant by "strongly typed"?

A) Every variable must have an associated type before you can use it
B) Variables can be used without declaring their type
C) Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type
D) Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be
E) Variables are allowed to change types during their existence in the program but only if the change is to a narrower type
سؤال
The values of (double) 5 / 2 and (double) (5 / 2) are identical.
سؤال
As presented in the Software Failure, the root cause of the Mars Climate Orbiter problem was

A) the cost of the project
B) an inability to track the orbiter at long distances
C) atmospheric friction
D) a communication issue between subsystems
E) none of the above
سؤال
If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns True.
سؤال
A variable of type boolean will store either a 0 or a 1.
سؤال
A double is wider than a float and a float is wider than an int.
سؤال
Java is able to represent 255 * 255 * 255 = 16,581,375 distinct colors.
سؤال
Provide an example of how you might use a boolean, a float, a char, a String, and an int.
سؤال
If x is the String "Hi There", then x.toUpperCase( ).toLowerCase( ); will return the original version of x.
سؤال
You cannot cast a String to be a char and you cannot cast a String which stores a number to be an int, float or double.
سؤال
The Java graphics coordinate system is similar to the coordinate system one finds in mathematics in every respect.
سؤال
Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use either the Scanner or Math classes, you pass messages directly to the class name, as in Math.abs( ) or scan.nextInt( ).
سؤال
As explained in the Software Failure, the Mars Lander most likely crash landed when its descent engines cut off too high over the Mars surface.
سؤال
If String name = "George W. Bush"; then the instruction name.length( ); will return 14.
سؤال
What is wrong with the following assignment statement?
Assume x and y are both String objects.
String z = x.equals(y);
سؤال
Write an output statement which will output the following characters exactly as shown: / ' \" / ' \
سؤال
What are the syntax errors from the following program?
public class Enigma
{
public static void main(String[ ] args)
{
System.out.println("Input a String");
String x = scan.nextString( );
int size = x.length;
char last = x.charAt(size);
System.out.println("The last character in your string ", x, " is ", last);
}
}
سؤال
Given two points in an applet represented by the four int variables x1, y1, x2 and y2, write a paint method to draw a line between the two points and write the location of the two points next to the two points.
سؤال
Assume that a = "1", b = "2", y = 3 and z = 4. How do the following two statements differ?
System.out.println(a + b + y + z);
System.out.println(y + z + a + b);
سؤال
Using the various String methods, manipulate a String called current to be current's last character followed by the remainder of its characters in order, placing the result in a String called rearranged.
سؤال
Provide three examples of code using assignment statements where one assignment statement would result in a syntax error, one would result in a logical error, and one would result in a run-time error.
سؤال
An applet is 200x200. Write the Strings "North", "South", "East", and "West" at the four edges of the applet where they should appear as if on a map. Use the color black for the text.
سؤال
An employer has decided to award a weekly pay raise to all employees by taking the square root of the difference between his weight and the employee's weight. For instance, an employee who weighs 16 pounds less than the employer will get a $4 per week raise. The raise should be in whole dollars (an int). Assume that employerWeight and employeeWeight are both int variables that have been input, write an assignment statement to compute the int value for raise.
سؤال
How many ways are there to test to see if two String variables, a and b, are equal to each other if we ignore their case (for instance, "aBCd" would be considered equal to "ABcd").
سؤال
Write a program which will input an int value x, and compute and output the values of 2ˣ and x¹⁰ as int values.
سؤال
How do the statements "import java.util.*;" and "import java.util.Random;" differ from each other?
سؤال
Given four int values, x1, x2, y1, y2, write the code to compute the distance between the two points (x1, y1) and (x2, y2), storing the result in the double distance.
سؤال
Write an assignment statement to compute the gas mileage of a car where the int values miles_traveled and gallons_needed have already been input. The variable gas_mileage needs to be declared and should be a double.
سؤال
Explain, in words, what the following statement computes:
int z = (int) Math.ceil(Math.sqrt(x) / Math.sqrt(y));
سؤال
Write the paint method for an applet so that it contains 4 concentric circles (each circle is inside the previous circle), where the largest circle is bounded by a 400x400 box and the smallest is bounded by a 100x100 box. Each circle is centered on an applet that is 400x400. Make each circle a different color of your choice.
سؤال
Write a program that will input some number of cents (less than 100) and output the number of quarters, dimes, nickels and pennies needed to add up to that amount.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/77
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 2: Data and Expressions
1
If x is an int and y is a float, all of the following are legal except which assignment statement?

A) y = x;
B) x = y;
C) y = (float) x;
D) x = (int) y;
E) all of the above are legal
B
Explanation: B) Since x is an int, it cannot except a float unless the float is cast as an int. There is no explicit cast in the assignment statement in B. In A, a cast is not necessary because a float (y) can accept an int value (x), and in C and D, explicit casts are present making them legal.
2
Which of the following is True regarding the mod operator, %?

A) It can only be performed on int values and its result is a double
B) It can only be performed on int values and its result is an int
C) It can only be performed on float or double values and its result is an int
D) It can only be performed on float or double values and its result is a double
E) It can be performed on any numeric values, and the result always is numeric
E
Explanation: E) Mod, or modulo, returns the remainder that results from a division. The remainder is always is numeric. Although usually integer values are used, the % operator may be used on all kinds of numeric data.
3
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
A reasonable documentation comment for this program might be

A) // a program that demonstrates the differences between print, println and how + works
B) // a program that outputs a message about Texas
C) // a program that demonstrates nothing at all
D) // a program that outputs the message "Here There Everywhere But not in Texas"
E) // a program that contains three output statements
A
Explanation: A) Remember that comments should not state the obvious (ruling out D and E) but instead should explain what the program is doing or why. This program demonstrates print and println and +.
4
The word println is a(n)

A) method
B) reserved word
C) variable
D) class
E) String
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
5
Given the following assignment statement, which of the following answers is True regarding the order that the operators will be applied based on operator precedence?
A = (b + c) * d / e - f;

A) *, /, +, -
B) *, +, /, -
C) +, *, /, -
D) +, /, *, -
E) +, -, *, /
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
6
What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
7
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
The program will print the word "Here" and then print

A) "There Everywhere" on the line after "Here"
B) "There" on the line after "Here" and "Everywhere" on the line after "There"
C) "There Everywhere" on the same line as "Here"
D) "ThereEverywhere" on the same line as "Here"
E) "ThereEverywhere" on the line after "Here"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
8
If you want to output the text "hi there", including the quote marks, which of the following could do that?

A) System.out.println("hi there");
B) System.out.println(""hi there"");
C) System.out.println("\"hi there");
D) System.out.println("\"hi there\"");
E) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
9
A Java variable is the name of a

A) numeric data value stored in memory
B) data value stored in memory that can not change during the program's execution
C) data value stored in memory that can change its value but cannot change its type during the program's execution
D) data value stored in memory that can change both its value and its type during the program's execution
E) data value or a class stored in memory that can change both its value and its type during the program's execution
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
10
Assume that x, y, and z are all integers (int) equal to 50, 20, and 6 respectively. What is the result of x / y / z?

A) 0
B) 12
C) 16
D) A syntax error as this is syntactically invalid
E) A run-time error because this is a division by 0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
11
A cast is required in which of the following situations?

A) using charAt to take an element of a String and store it in a char
B) storing an int in a float
C) storing a float in a double
D) storing a float in an int
E) all of the above require casts
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
12
Of the following types, which one cannot store a numeric value?

A) int
B) byte
C) float
D) char
E) all of these can store numeric values
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
13
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
How many lines of output are provided by this program?

A) 1
B) 2
C) 3
D) 4
E) 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
14
Use the following class definition to answer the questions below.
public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
The final println command will output

A) "But not in Texas"
B) "But notin Texas"
C) "But not" on one line and "in Texas" on the next line
D) "But not+in Texas"
E) "But not + in Texas"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
15
If you want to store into the String name the value "George Bush", you would do which statement?

A) String name = "George Bush";
B) String name = new String("George Bush");
C) String name = "George" + " " + "Bush";
D) String name = new String("George" + " " + "Bush");
E) Any of the above would work
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
16
What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5?

A) 15
B) 105
C) 10 5
D) x+y
E) An error since neither x nor y is a String
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
17
What will be the result of the following assignment statement? Assume b = 5 and c = 10.
Int a = b * (-c + 2) / 2;

A) 30
B) -30
C) 20
D) -20
E) -6
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
18
What value will z have if we execute the following assignment statement?
Float z = 5 / 10;

A) z will equal 0.0
B) z will equal 0.5
C) z will equal 5.0
D) z will equal 0.05
E) none of the above, a run-time error arises because z is a float and 5 / 10 is an int
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
19
Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ________ lines of text

A) 1
B) 2
C) 3
D) 4
E) 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
20
Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying

A) c = a.length( ) + b.length( );
B) c = (int) a + (int) b;
C) c = a.concat(b);
D) c = b.concat(a);
E) c = a.plus(b);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
21
Assume that x is a double that stores 0.362491. To output this value as 36%, you could use the NumberFormat class with NumberFormat nf = NumberFormat.getPercentInstance( ); Which of the following statements then would output x as 36%?

A) System.out.println(x);
B) System.out.println(nf);
C) System.out.println(nf.x);
D) System.out.println(nf.format(x));
E) System.out.println(format(x));
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
22
Which library package would you import to use the class Random?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
23
Which of the following would return the last character of the String x?

A) x.charAt(0);
B) x.charAt(last);
C) x.charAt(length(x));
D) x.charAt(x.length( )-1);
E) x.charAt(x.length( ));
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
24
For the following questions, refer to the class defined below:
import java.util.Scanner;
public class Questions
{
public static void main(String[ ] args)
{
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x = scan.nextInt( );
System.out.println("Enter another integer value");
y = scan.nextInt( );
System.out.println("Enter a third integer value");
z = scan.nextInt( );
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
What is output if x = 0, y = 1 and z = 1?

A) 0
B) 0.0
C) 0.6666666666666666
D) 0.6666666666666667
E) 0.67
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
25
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The figure drawn in this applet is

A) a blue square
B) a blue square with two white lines drawn horizontally through it
C) a blue square with two white lines drawn diagonally through it
D) a blue square with two white lines drawn vertically through it
E) a white square with two blue lines drawn vertically through it
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
26
For the following questions, refer to the class defined below:
import java.util.Scanner;
public class Questions
{
public static void main(String[ ] args)
{
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x = scan.nextInt( );
System.out.println("Enter another integer value");
y = scan.nextInt( );
System.out.println("Enter a third integer value");
z = scan.nextInt( );
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
Questions33_34 computes

A) The correct average of x, y and z as a double
B) The correct average of x, y and z as an int
C) The average of x, y, and z as a double, but the result may not be accurate
D) the sum of x, y and z
E) the remainder of the sum of x, y and z divided by 3
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
27
Consider the double value likelihood = 0.013885. What would be output if DecimalFormat dformatter = DecimalFormat("0.00##"); and you execute System.out.println(df.format(likelihood)); ?

A) 0.013885
B) 0.0139
C) 0.014
D) )0139
E) )014
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
28
In order to create a constant, you would use which of the following Java reserved words?

A) private
B) static
C) int
D) final
E) class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
29
Consider the following paint method and answer the questions below:
public void paint(Graphics page)
{
page.setColor(Color.blue);
page.fillRect(50, 50, 100, 100);
page.setColor(Color.white);
page.drawLine(50, 50, 150, 150);
page.drawLine(50, 150, 150, 50);
page.setColor(Color.black);
page.drawString("A nice box", 50, 170);
}
The String "A nice box" is drawn

A) above the box
B) to the left of the box
C) to the right of the box
D) below the box
E) inside the box
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
30
You specify the shape of an oval in a Java applet by defining the oval's

A) arc locations
B) center and radius
C) bounding box
D) foci
E) none of the above, it is not possible to draw an oval in a Java applet
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
31
What value will z have if we execute the following assignment statement?
Int z = 50 / 10.00;

A) 5
B) 5.0
C) 50
D) 10
E) none of the above, a run-time error arises because z is an int and 50 / 10.00 is not
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
32
Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?

A) Math.sqrt(x*x);
B) Math.sqrt((int) x);
C) Math.sqrt(Math.abs(x));
D) Math.abs(Math.sqrt(x));
E) Math.sqrt(-x);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which library package would you import to use NumberFormat and DecimalFormat?

A) java.beans
B) java.io
C) java.lang
D) java.text
E) java.util
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
34
If you want to output a double so that at least 1 digit appears to the left side of the decimal point and exactly 1 digit appears to the right side of the decimal point, which pattern would you give a DecimalFormat variable when you instantiate it?

A) "0.0"
B) "0.#"
C) "0.0#"
D) "0.##"
E) "#.#"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
35
Suppose that String name = "Frank Zappa". What will the instruction name.toUpperCase( ).replace('A', 'I'); return?

A) "FRANK ZAPPA "
B) "FRINK ZIPPI"
C) "Frink Zippi"
D) "Frank Zappa"
E) "FrInk ZIppI"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
36
If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following sets of commands might you use?

A) page.setColor(Color.green); page.fillRect(50, 50, 100, 100);
Page.setColor(Color.red);
Page.fillOval(60, 60, 80, 80);
B) page.setColor(Color.red); page.fillOval(60, 60, 80, 80);
Page.setColor(Color.green);
Page.fillRect(50, 50, 100, 100);
C) page.setColor(Color.green); page.fillRect(60, 60, 80, 80);
Page.setColor(Color.red);
Page.fillOval(50, 50, 100, 100);
D) page.setColor(Color.red); page.fillOval(50, 50, 100, 100);
Page.setColor(Color.green);
Page.fillRect(60, 60, 80, 80);
E) any of the above would accomplish this
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
37
Using getCurrencyInstance( ) formats a variable, automatically inserting

A) decimal point for cents
B) dollar sign
C) percent sign
D) all three
E) A and B but not C
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
38
If the String major = "Computer Science", what is returned by major.charAt(1)?

A) 'C'
B) 'o'
C) 'm'
D) "C"
E) "Computer"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
39
If a, b, and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to

A) 0
B) 4
C) 5
D) -5
E) 23
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
40
The Random class has a method nextFloat( ) which returns a random float value between

A) -1 and +1
B) 0 and 1
C) 0 and 99
D) 1 and 100
E) -2,147,483,648 and +2,147,483,647
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
41
Many Java drawing shapes are specified using a bounding rectangle.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
42
In order to generate a random number, you must use Math.random( ).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
43
In Java, 'a' and 'A' are considered to be different values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
44
Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a float value and input it using the Scanner class into the variable y.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
45
There are three ways that data conversion may occurby assignment, by promotion, by casting.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
46
If x is a string, then x = new String("OH"); and x = "OH"; will accomplish the same thing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
47
Java is a strongly typed language. What is meant by "strongly typed"?

A) Every variable must have an associated type before you can use it
B) Variables can be used without declaring their type
C) Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type
D) Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be
E) Variables are allowed to change types during their existence in the program but only if the change is to a narrower type
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
48
The values of (double) 5 / 2 and (double) (5 / 2) are identical.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
49
As presented in the Software Failure, the root cause of the Mars Climate Orbiter problem was

A) the cost of the project
B) an inability to track the orbiter at long distances
C) atmospheric friction
D) a communication issue between subsystems
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
50
If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns True.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
51
A variable of type boolean will store either a 0 or a 1.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
52
A double is wider than a float and a float is wider than an int.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
53
Java is able to represent 255 * 255 * 255 = 16,581,375 distinct colors.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
54
Provide an example of how you might use a boolean, a float, a char, a String, and an int.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
55
If x is the String "Hi There", then x.toUpperCase( ).toLowerCase( ); will return the original version of x.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
56
You cannot cast a String to be a char and you cannot cast a String which stores a number to be an int, float or double.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
57
The Java graphics coordinate system is similar to the coordinate system one finds in mathematics in every respect.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
58
Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use either the Scanner or Math classes, you pass messages directly to the class name, as in Math.abs( ) or scan.nextInt( ).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
59
As explained in the Software Failure, the Mars Lander most likely crash landed when its descent engines cut off too high over the Mars surface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
60
If String name = "George W. Bush"; then the instruction name.length( ); will return 14.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
61
What is wrong with the following assignment statement?
Assume x and y are both String objects.
String z = x.equals(y);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
62
Write an output statement which will output the following characters exactly as shown: / ' \" / ' \
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
63
What are the syntax errors from the following program?
public class Enigma
{
public static void main(String[ ] args)
{
System.out.println("Input a String");
String x = scan.nextString( );
int size = x.length;
char last = x.charAt(size);
System.out.println("The last character in your string ", x, " is ", last);
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
64
Given two points in an applet represented by the four int variables x1, y1, x2 and y2, write a paint method to draw a line between the two points and write the location of the two points next to the two points.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
65
Assume that a = "1", b = "2", y = 3 and z = 4. How do the following two statements differ?
System.out.println(a + b + y + z);
System.out.println(y + z + a + b);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
66
Using the various String methods, manipulate a String called current to be current's last character followed by the remainder of its characters in order, placing the result in a String called rearranged.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
67
Provide three examples of code using assignment statements where one assignment statement would result in a syntax error, one would result in a logical error, and one would result in a run-time error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
68
An applet is 200x200. Write the Strings "North", "South", "East", and "West" at the four edges of the applet where they should appear as if on a map. Use the color black for the text.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
69
An employer has decided to award a weekly pay raise to all employees by taking the square root of the difference between his weight and the employee's weight. For instance, an employee who weighs 16 pounds less than the employer will get a $4 per week raise. The raise should be in whole dollars (an int). Assume that employerWeight and employeeWeight are both int variables that have been input, write an assignment statement to compute the int value for raise.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
70
How many ways are there to test to see if two String variables, a and b, are equal to each other if we ignore their case (for instance, "aBCd" would be considered equal to "ABcd").
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
71
Write a program which will input an int value x, and compute and output the values of 2ˣ and x¹⁰ as int values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
72
How do the statements "import java.util.*;" and "import java.util.Random;" differ from each other?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
73
Given four int values, x1, x2, y1, y2, write the code to compute the distance between the two points (x1, y1) and (x2, y2), storing the result in the double distance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
74
Write an assignment statement to compute the gas mileage of a car where the int values miles_traveled and gallons_needed have already been input. The variable gas_mileage needs to be declared and should be a double.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
75
Explain, in words, what the following statement computes:
int z = (int) Math.ceil(Math.sqrt(x) / Math.sqrt(y));
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
76
Write the paint method for an applet so that it contains 4 concentric circles (each circle is inside the previous circle), where the largest circle is bounded by a 400x400 box and the smallest is bounded by a 100x100 box. Each circle is centered on an applet that is 400x400. Make each circle a different color of your choice.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
77
Write a program that will input some number of cents (less than 100) and output the number of quarters, dimes, nickels and pennies needed to add up to that amount.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.