PROGRAMMING QUESTIONS STUDY

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What does the myString variable contain after the following code sequence: String myString = "hello number "; // note the space at the end of the string myString = myString + myString.length();

"hello number 13"

If a program "Tester" is run from the command line as shown below, what is the value of args[0] in the function void main(String[] args)? java Tester sing a song

"sing"

What string is produced by this expression: String.format("%4$s %3$s %2$s %1$s",4,3,2,1)

"1 2 3 4"

What string is produced by this expression: String.format("%1$s and %1$5s and %1$-5s",1,2,3))

"1 and 1 and 1 "

What is the difference between the "==" and "=" operators?

"==" tests for equality, "=" is an assignment

When using an if() statement, what must go within the parentheses?

A logical expression

What is stored in the result variable by the following code? int result = Integer.parseInt("forty-two");

A run-time exception will be shown

If you use a school computer to play online games, what might you be violating?

Acceptable Use Policy

Which of the following is a good example of a software application? a. A printer driver b. An Integrated Development Environment (IDE) c. Mac OS d. Linux

An Integrated Development Environment (IDE)

Which of the following concepts are commonly found in EULAs? a. Licensed, not sold b. Use at your own risk c. Don't copy or sell d. All of these

D. All of the above

The following logical expression illustrates what concept? !( A || B) = !A && !B

DeMorgan's Theorem

Which of the following principles are not part of the Association for Computing Machinery (ACM) list of ethical standards for computer programmers? a. Contribute Positively b. Respect Privacy c. Respect Property Rights d. Deliver on Time

Deliver on Time

If you want to install a new type of printer on your computer, what kind of software might you need to make it work?

Device driver

How would you declare and initialize a primitive wrapper class for the double data type that contains the value 1.0?

Double myDouble = new Double(1.0);

What is stored in the result variable by the following code? String result = String.format("I'll take %5s please", "2");

I'll take 2 please

When might you want to use a do-while() loop instead of a while() loop?

If you are sure the loop body should execute at least once

How many times will the following do-while() loop execute? boolean done = true; do { done = false; } while (!done);

Infinite number of times

Why is Visual Basic sometimes used for "Rapid Application Development"?

It's very easy to get a program up and running quickly

What properties on the Java numeric wrapper classes hold the largest and smallest possible values for that data type?

MAX_VALUE and MIN_VALUE

Which two operating systems appeared in the mid-1980's with graphical user interfaces?

Microsoft Windows and Mac OS

You are working for a company that has created a program that is gathering information from the user without their knowledge. Your boss gives you full permission to use this information and to share it with other companies. Should you do so?

No, you may only use or share private information when you have obtained the owner's explicit permission for the use of that information.

Consider the following three string variables: String myString1 = "not so loud!"; String myString2 = "NOT SO LOUD!"; String myString3 = "No thanks"; What is returned by the expression myString2.substring(1)

OT SO LOUD!

Which operating systems are sold and supported by a major company instead of free and open-source?

Windows and Mac OS

What is wrong with this if() statement if "a" and "b" are both ints? if (a = b)

You cannot use an assignment statement as a logical expression

Why is it important to validate any expected parameters from the command-line?

Your program may encounter an exception if you try to use a parameter that does not exist in the args array

If the user enters data "awesome" when you prompt for a number, what will happen when you call nextInt() to read the data?

Your program will get an InputMismatchException

What happens if you call Scanner.nextInt() and the user has entered "abc"?

Your program will throw an exception

What text string is printed to the screen with this statement? System.out.println("#\"##\\#");

d. #"##\#

Which of the following update expressions is valid to replace the ??? phrase within the for() loop below? for (int i=0; i<10; ???) Select one: a. i = i - 5 b. i++ c. i = i * 2 d. All of these are valid

d. All of these are valid

Which of the following for() loops will execute 10 times? a. for (int index = 0; index < 10; index++) b. for (int index = 1; index <= 10; index++) c. for (int index = 10; index < 20; index++) d. All of these will execute 10 times

d. All of these will execute 10 times

Which loop is always the best choice: for(), while(), or do-while()? Select one: a. do-while() b. for() c. while() d. It depends on the needs of your program

d. It depends on the needs of your program

Which of the following expressions will read the first parameter passed into the main(String[] args) function? a. string[0] b. args c. args[1] d. args[0]

d. args[0]

What will be the output of the following for() loop: String target = "millisecond"; for (int i=0; i<target.length(); i++) { if (target.charAt(i) == 'l') break; else System.out.print(target.charAt(i));}

mi

What physical component forms the backbone of the computer hardware system, interconnecting and supporting many other components?

motherboard

When will the following code print "you can drive" ? if (age >= 16){ System.out.println("you need a learner's permit"); }else if (age >= 18){ System.out.println("you can drive");}

never

What Scanner function would you call to get a double (floating point) value from the user input?

nextDouble()

What Scanner function would you call to get a full line of user input?

nextLine()

What is the default value of a reference variable after it is declared?

null

In Java 7, what values are valid as a case statement selector?

numbers, letters, or strings

Which hardware platform contains an integrated monitor and touch screen instead of a keyboard?

tablet

Given the code below, is it true that myString1.equals(myString2) and myString2.equals(myString1) will produce the same result? String myString1 = "abc"; String myString2 = "ABC";

true

If "a = 3" and "b = 5", what is the result of the following logical expression? (a > b) || (b == 5)

true

What is stored in the result variable by the following code? boolean myBool = true;String result = Boolean.toString(myBool);

true

You cannot be certain ahead of time how many command-line parameters a Console program will receive.

true

What security measure would you most likely use to uniquely identify a person?

login (username/password)

Consider the following three string variables: String myString1 = "not so loud!"; String myString2 = "NOT SO LOUD!"; String myString3 = "No thanks"; What are the minimum and maximum valid character index values in myString3?

0 and 8

How many "else if ()" clauses can you have after an if() expression?

0, 1, or more

If you type the command below on the command line, how many parameters will be passed to the Mystery program? java Mystery data

1

After the following statement, what value is stored in the myInteger variable? int myInteger;

0

What will be the output of the following for() loop: for (int i=0; i<10; i+=3){ System.out.print(i * 3 + " ");}

0 9 18 27

What symbols make up a computer's native Machine Language?

0 and 1

What is the result of the following mathematical expression? 2 * ( (6 + 4) / 2)

10

What is the result of the following mathematical expression? 2 * 6 + 4 / 2

14

How many copies of the value 42 are created by this code? int myInt1 = 42; int myInt2 = myInt1; int myInt3 = myInt2;

3

Given the code below, what is the value stored in result? String myString = "quiz"; int result = myString.length();

4

Consider the following three string variables: String myString1 = "not so loud!"; String myString2 = "NOT SO LOUD!"; String myString3 = "No thanks"; What is returned by the expression myString1.lastIndexOf("o")

8

After the following code is run: double num1 = 9.6; int num2 = (int)num1; What is the value in num2?

9

Which of the following is a valid logical expression (assuming "a" and "b" are ints)? a. (a > (1 + b)) b. All are valid logical expressions c. (a == 3) d. ((a + 3) > (b + 2))

All are valid logical expressions

Which language was created by adding object-oriented concepts added to an earlier language?

C++

What do you need to do after a hasNextDouble() function returns false, meaning the user has entered something other than a double value?

Call next() to read the unexpected data from the stream as a String

If you use one of the next() methods to retrieve a numeric data type, what can you do to clear any newline (\n) the user may have entered from the input stream?

Call nextLine()

What should you remember to do after using any combination of the hasNext() and next() functions?

Call nextLine() to clear the newline from the input stream

What is stored in the result variable by the following code? String result = "Captain," + "incoming" + "message";

Captain,incomingmessage

What's wrong with always using the largest possible data type to store your data?

Larger data types take more memory

Which of the following operating system is an "open-source" operating system? a. Linux b. Windows 8 c. Apple's Mac OS X d. Microsoft Windows

Linux

Which type of software license allows you free access to the program's original source code?

Open Source

What might you want to do before calling one of the Scanner input methods?

Print a message to the console so the user knows what to do

What happens if you leave out the "break" keyword within a case statement?

Program flow will continue through to the next case

Which of the following components can be used to easily transfer data between computers? a. RAM b. Motherboard c. Hard Drive d. Removable storage media

Removable storage media

How to you create a new Scanner object to get user input from the console?

Scanner input = new Scanner(System.in);

Which line of code will result in myString = "1.7320508" ? a. String myString = Double("1.7320508"); b. String myString = String.format(1.7320508); c. String myString = Double.toString(1.7320508); d. String myString = Double.convert(1.7320508);

String myString = Double.toString(1.7320508);

Which company invented Java, and in what year?

Sun Microsystems, in the 1990's

Which object is used to write output to the console?

System.out

What limits a numeric data type's precision and range?

The number of bytes in memory the data occupies

Given the following while() loop, which statement is true assuming A,B,C,D are int variables and A > B? while ( ( A >= B) || ( (C - D) > 10)){ System.out.println(A + B + C + D);}

The program will never leave the loop body

Why might you want to install a video card into your system?

To get higher quality and higher performance in your graphical output

Which statement correctly assigns the character value 'x' to the char variable myChar? a. char myChar = 'x'; b. myChar as char = 'x'; c. character myChar = "x"; d. char myChar = "x";

a. char myChar = 'x';

What is the difference between the print() and println() functions? a. println() will automatically wrap to the next line; print() will not b. print() will automatically wrap to the next line; println() will not c. println() will accept any string; print() will ony take variables d. println() is only for output; print() can also be used to gather user input

a. println() will automatically wrap to the next line; print() will not

What is the best naming style to use for a variable that contains a count of the number of frogs in a pond? a. frogCount b. All styles are equally valid; just be consistent c. FrogCount d. frog_count

b. All styles are equally valid; just be consistent

How would you print the following string to the console? "Nonsense", she said! a. System.out.println("Nonsense", she said!); b. System.out.println("\"Nonsense\", she said!"); c. System.out.println(\"Nonsense\", she said!); d. System.out.println(""Nonsense"", she said!");

b. System.out.println("\"Nonsense\", she said!");

Which data type can hold exactly two different values?

boolean

Which data type would you use to hold a true or false value?

boolean

What is the smallest data type that can hold the value 126?

byte

Consider the following three string variables: String myString1 = "not so loud!"; String myString2 = "NOT SO LOUD!"; String myString3 = "No thanks"; Which expression will return true? a. myString3.equalsIgnoreCase("NO THANKS") b. myString2.equalsIgnoreCase(myString1) c. They all return true d. myString1.equalsIgnoreCase(myString2)

c. They all return true

Which of the following variable names is invalid? a. int b. SHOO FLY c. They are all invalid. d. 1place

c. They are all invalid.

Which assignment statement correctly assigns a decimal value to the variable "myFloat" that was already declared as a float data type? a. myFloat = 2.1(float); b. myFloat = 2.1; c. myFloat = 2.1F; d. myFloat = 2.1D;

c. myFloat = 2.1F;

Which of the following expressions should be used to determine if the contents of myString1 are equal to the contents of myString2? a. myString1 = myString2 b. myString1 == myString2 c. myString2.equals(myString1) d. They all work equally well

c. myString2.equals(myString1)

What keyword can be used to execute a block of logic when the tested "if" expression returns false?

else

Given the code below, what is the value stored in result? String myString = "quiz"; boolean result = myString.contains("Z");

false

Given the following code, what is the result of calling myString1.equals(myString2)? String myString1 = "abc";String myString2 = "ABC";

false

What is the result of calling hasNextByte() on your Scanner object if the user has entered "abc" on the console?

false

What keyword do you use to ensure a variable can never change values while your program is running?

final

Which of the following is an example of secondary memory? a. ROM b. Motherboard c. Hard Drive d. RAM

hard drive

What Scanner function can you call to see if a "short" data value is currently waiting on the input stream?

hasNextShort()

Which of the following keywords can be used to test a condition and make decisions in your program? a. compare b. if c. assert d. check

if

Which if() statement within the function void main(String[] args) will ensure you have 3 or more command-line parameters?

if (args.length() > 2)

If you needed to hold the integer value 36,493, which numeric data type would you use?

int

Which line of code will result in myInt = 42 ? Select one: a. int myInt = "42"; b. int myInt = Integer.parseInt ("42"); c. int myInt = Integer("42").toString(); d. int myInt = Integer.toString("42");

int myInt = Integer.parseInt ("42");

What are the two main categories of numeric data types as stored in computers?

integer and floating point

What package contains the Scanner class?

java.util


संबंधित स्टडी सेट्स

World History Part 2: The Building of Global Empires

View Set

Accounting Final- midterm questions

View Set

Lewis Chapter 66 - Shock Questions

View Set

patho cardiovascular disorders quiz

View Set

U.S Government Unit 5: International Relations

View Set

Anatomical Terms- HSF Laboratory

View Set

Asia Economic Systems of the World exam

View Set