Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

b) Which of the following are correct literals for characters? '1', u345dE,u3fFa', b, 1) Write the code that generates a random lowercase letter m) What

image text in transcribedimage text in transcribedimage text in transcribed

b) Which of the following are correct literals for characters? '1', u345dE","\u3fFa', "b, 1) Write the code that generates a random lowercase letter m) What is wrong in the following code? import java.util.Scanner: public class Test public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int value - input sextinto: System.out.println("The value is " + value); System.out.print("Enter a line: "); String line input.nextLine: System.out.println("The line is " + line): 2. 2 points) State whether each of the following is true or false. If false, explain why. a) The following are all valid variable names_under-bar...928134, 15, 17, her_saless, his Saccount total, a, b, c, 2 and 22. b) The following are all invalid variable names: 39, 87,6712, 122 and 2h. 3. 2 points) Write an expression that obtains a random integer between 34 and 55 inclusive. Write an expression that obtains a random integer between 0 and 999. 4. (2 points) Can the following conversions involving casting be allowed? If so, find the converted result charc='A int i = (int): float f-1000.34, int i = (int) double d - 1000.34 inti- (int)d; int i = 97: charc =(char)i: a. c. e. 5. (5 points) Suppose that s1, 52 and 53 are three strings, given as follows: String s1 -"Welcome to Java": String 2 "Programming is fun": String s3 "Welcome to Java"; What are the results of the following expressions? si 32 b. s1 - 33 $1.equals(2) d. s1.equals(3) s1.compareTo(2) f. s2.compare To(3) $2.compareTo(x2) h. s1.charAt(0) s1.length ). $1.toLowerCase 6. (4 points) Suppose that s1 and 2 are two strings. Which of the following statements or expressions are incorrect? String s1 - "Welcome to Java", String s2 = "Welcome to Java", String s3 - 51 +82; String s3 = s1 - 2 g 1 si compareTo(s2); charc - 5100); char c = sh.charAt(s1.length(); 7. (4 points) Show the output of the following statements. (a) System.out.printf("amount is %fn", 32.32); 6) System.out.printf("amount is %5.2f%n", 32.327); (c) System.out.printf("%6b ".(1 > 2)); (d) System.out.printf"%s ", "Java"); (e) System.out.printf("%-60%s ", (1 > 2), "Java"); (1) System.out.printf("%bb%-8s ", (1 > 2), "Java"); System.out.printf("%,50 %,6.1fn", 312342, 315562.932); (h) System.out.printf("%05d %06.1fn". 32, 32.32); Programming Questions 8. 6 points) Write a program that inputs from the user the radius of a circle as an integer and prints the circle's diameter, circumference and area using the floating-point value 3.14159 for n. [Note: You may use the predefined constant Math PI for the value of 1. This constant is more precise than the value 3.14159. Class Math is defined in package java.lang. Classes in that package are imported automatically, so you do not need to import class Math to use it.] Use the following formulas (r is the radius): Diameter = 2 *r Circumference = 2 * pir Area = pi *r*1 Do not store the results of each calculation in a variable. Rather, specify each calculation as the value that will be output in a System.out.printf statement. The values produced by the circumference and area calculations are floating-point numbers. Such values can be output with the format specifier %f in a System out.printf statement. Enter radius: 12 Diameter is 24 Circumference is 75.398224 Area is 452.389342 9. ( points) Write a program that prompts the user to enter a Social Security number in the format DDD-DD-DDDD, where D is a digit. Your program should check whether the input is valid. Here are sample runs: Enter a SSN: 232-23-5435 Enter 232-23-5435 is a valid social security number Enter a SSN: 23-23-5435 enter 23-23-5435 is an invalid social security number 10.6 points) Assume that a vehicle plate number consists of three uppercase letters followed by four digits. Write a program to generate a plate number. A random vehicle plate number: XED8349

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions