SJU CSC 3405 - Console Input and Output

Unformatted text preview:

Chapter 2 Console Input and Output Multiple Choice)1 Valid arguments to the System.out object’s println method include:(a) “Anything with double quotes”(b) String variables(c) Variables of type int(d) All of the above)2 Which statement or group of statements produces the output: Java programming is fun!()a System.out.print(Java programming);System.out.print(is fun!);()b System.out.println(Java programming is fun!);()c System.out.println(“Java programming”);System.out.println(“ is fun!”);()d System.out.print(“Java programming”)System.out.println(“ is fun!”);)2 If a hyphen is added after the % in a format specifier, the output will be _________.()a Left justified()b Right justified()c Centered()d None of the above)3 The statement: System.out.printf("%6.2f", 597.7231); displays:()a 597.723()b 597.72()c 000597.72()d None of the above)4 The Java method printf is based on the ________ language.()a Pascal()b C++()c C()d ADA)5 The class NumberFormat allows you to specify a constant representing which country’s currency format should be used. To use this constant you must import:()a java.util.Locale()b java.util.Currency()c java.util.Properties()d None of the above.)6 Standard code libraries in Java are called:()a Methods()b Classes()c Packages()d Statements)7 What does the following code output?DecimalFormat percent = new DecimalFormat("0.00%");System.out.println(percent.format(0.308));()a 3.080%()b 30.80%()c .0308%()d 308.0%)8 What does the following code output?DecimalFormat dfQuestion = new DecimalFormat("#0.##E0");System.out.println(dfQuestion.format(12.7896987));()a 12.79E0()b 12.8E0()c 1.28E1()d .13E2)9 What Java package includes the class Scanner?()a awt()b swing()c io()d util True/False)1 Efficiency is lost in importing the entire package instead of importing the classes you use.)2 Every Java program automatically imports the java.util package.)3 The new line character is represented as ‘n’.)4 The method printf is used the same way as the method println but has the added feature that allows you to add formatting instructions.)5 The printf method can be used to output multiple formatted values.)6 The Scanner class has a method next that allows an entire line of string text to be read.)7 Echoing input is good programming practice because it can reveal problems in the input. Short Answer/Essay)1 Write a Java statement to display your name in the console window.)2 Write ONE Java statement to display your first and last name on two separate lines.)3 Write Java statements to apply currency formatting to the number 100. Indicate the package you need to import.)4 Write a Java program to create and display 57.32% using the DecimalFormat class. Include the necessary import statement to use the DecimalFormat class.)5 Explain the significance of the pattern string used by the DecimalFormat object, and give an example of a valid pattern.)6 What does it mean to prompt the user?)7 Why is echoing user input a good programming practice?)8 If there is no loss of efficiency in importing an entire Java package instead of importing only classes you use into your program, why would you not just import the entire package?)9 Write a complete Java console application that prompts the user for two numbers, multiplies the numbers, and then displays the result to the user.)10 What do the format specifiers d, f, e, g, s and c represent?)11 Write a Java statement to create and initialize a Scanner object named input.)12 What is whitespace and why is it import when reading input from the keyboard using the Scanner class?Chapter 2Console Input and Output Multiple Choice)1 Valid arguments to the System.out object’s println method include:(a) “Anything with double quotes”(b) String variables(c) Variables of type int(d) All of the above)2 Which statement or group of statements produces the output: Java programming is fun! ()a System.out.print(Java programming);System.out.print(is fun!);()b System.out.println(Java programming is fun!);()c System.out.println(“Java programming”);System.out.println(“ is fun!”);()d System.out.print(“Java programming”)System.out.println(“ is fun!”);)2 If a hyphen is added after the % in a format specifier, the output will be _________.()a Left justified()b Right justified()c Centered()d None of the above)3 The statement: System.out.printf("%6.2f", 597.7231); displays:()a 597.723()b 597.72()c 000597.72()d None of the above)4 The Java method printf is based on the ________ language.()a Pascal()b C++()c C()d ADA)5 The class NumberFormat allows you to specify a constant representing which country’s currency format should be used. To use this constant you must import:()a java.util.Locale()b java.util.Currency()c java.util.Properties()d None of the above.)6 Standard code libraries in Java are called:()a Methods()b Classes()c Packages()d Statements)7 What does the following code output?DecimalFormat percent = new DecimalFormat("0.00%");System.out.println(percent.format(0.308));()a 3.080%()b 30.80%()c .0308%()d 308.0%)8 What does the following code output?DecimalFormat dfQuestion = new DecimalFormat("#0.##E0");System.out.println(dfQuestion.format(12.7896987));3()a 12.79E0()b 12.8E0()c 1.28E1()d .13E2)9 What Java package includes the class Scanner?()a awt()b swing()c io()d util True/False)1 Efficiency is lost in importing the entire package instead of importing the classes you use.)2 Every Java program automatically imports the java.util package.)3 The new line character is represented as ‘\n’.)4 The method printf is used the same way as the method println but has the added feature that allows you to add formatting instructions.)5 The printf method can be used to output multiple formatted values.)6 The Scanner class has a method next that allows an entire line of string text to be read.)7 Echoing input is good programming practice because it can reveal problems in the input. Short Answer/Essay)1 Write a Java statement to display your name in the console window.)2 Write ONE Java statement to display your first and last name on two separate lines.)3 Write Java statements to apply currency formatting to the number 100. Indicate the package you need to import.)4 Write a Java program to create and display 57.32% using the DecimalFormat class. Include the necessary import statement to use the DecimalFormat class.)5 Explain the significance of the pattern string used by the DecimalFormat object, and give an


View Full Document

SJU CSC 3405 - Console Input and Output

Download Console Input and Output
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Console Input and Output and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Console Input and Output 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?