For this exercise, explore concepts with escape characters, concatenation, opera
ID: 3663898 • Letter: F
Question
For this exercise, explore concepts with escape characters, concatenation, operator precedence, methods, conversion, assignment, and syntax. For each example, answer questions, identify and correct any errors and state the concept being demonstrated. Output must be displayed in order to view results. You may choose how you wish to display the output. Use info boxes and reference the textbook to create info boxes as required. Add your own info boxes to enhance this assignment so that it will be an effective study guide.I only need help with 14- 18 . thank you
public class ClassName
object.methodName(parameters);
Class.object.methodName(Parameters);
System.out.println(“Output to printer”);
{
public static void main(String[] args)
{// statements ending with a semicolon;
System.out.println(“Output to Printer here”):
}
Escape characters
backspace
tab
newline
carriage return
” double quote
’ single quote
\ backslash
}
1. In quotes using escape characters print
“Hello World”
2. Using escape characters print the following on separate lines
Hello
World
3. Concatenate the following text and numbers by typing in the code. Exactly what
is displayed? Why?
‘A’ + “Lucky number” “3” 4/5*23 + 20%5 “ wins the lottery!”
4. Print the following message using the System.out.print method
Hurricane Issac is pummeling 100 % of New Orleans.
5. Print the same message using the newline escape character.
6. Print the following message three times using the carriage return character.
Cuba was flooded by hurricane Ivan.
7. Print the following message using the System.out.print() method and escape characters.
Java identifiers are words used in writing programs. Three types:
· Reserved words (predefined) for special purposes in the Java language
· Variables made up by programmer
· Words in the libraries chosen by another programmer
Java source code is software that can be read by a person.
Java object code has strange characters.
Object code is also compiled code.
The compiled bytecode can be run on any architecture.
“The bytecode is similar to machine language!”
8. Exactly type the following calculations and print the results.
What is the output?
result = ((9 + 8) % 3) - 4
9. Exactly type the following calculations and print the results.
What is the difference from the previous problem
result = ((9 + 8 % 3) - 4;
Assignment is always
Left = Right
10. Create and initialize integer and a double variable.
Assign the value of the integer to the double. What type of conversion
is this? Print the results.
11. Modify the assignment statement to assign the double to the integer variable.
Print the results. What type of conversion is this?
12. Create and initialize a constant integer. In the next java statement,
assign an integer to the constant. Use the correct syntax for constants.
Enter the Java syntax for constants:
Print results.
Java variable names are case-sensitive
and the style for variables is lower case.
CONSTANTS style are in upper case.
Class names style start with a Capital.
13. Create variables and print the results.
int itestLC = 20;
int iTESTLC;
14. Assign a new integer value to itestLC and print the values
for itestLC and ITESTLC. How does this prove that Java is
case sensitive?
15. Test the Boolean assignment. Enter the statements and print the
results. What errors do you encounter?
Boolean answer = true; //Capital B indicates the class Boolean
boolean answer = “false”;//lower case b for primitive data types.
16. Assignment Conversion: only widening conversions can be
accomplished. Enter the following statements and print all values
between each statement. What errors do you encounter? How must float variables be declared different from double data types?
int dollars = 5;
float money;
float bigBucks = 99999.9;
money = dollars;
dollars = bigBucks;
17. Arithmetic Promotion numeric types are converted during certain mathematic calculations. The conversion is done during the calculation and the original variable types remain the same after the calculation is performed. . Enter the following statements and print all values between each statement.
float quotient, dividend = 100.05;
int divisor = 5;
quotient = dividend / divisor;
18. Casting is an explicit conversion by placing the desired type in parenthesis before the variable to be converted. Again, the type of the variable being “casted” is not changed after the calculation is performed. . Enter the following statements and print all values between each statement.
float quotient, dividend = 100.05;
int divisor = 5;
quotient = dividend / (float) divisor;
Rules for naming Java variables:
Primitive Data Types
Type
Storage/value
boolean
true false
byte
8 bits
short
16 bits
int
32 bits
long
64 bits
float
32 bits
double
64 bits
object.methodName(parameters);
Class.object.methodName(Parameters);
System.out.println(“Output to printer”);
Explanation / Answer
14.
itestLC = 80; // assigining new value
System.out.print(itestLC); // output : 80
System.out.print(iTESTLC); // output: 0
see here, if you ignore case of letter in itestLC and iTESTLC, then both are same, but assigining the value to one of them will not affect other, means both are different, so they are case sensitive.
15.
Boolean answer = true; // fine, output : true
boolean answer = “false”; // two errors- 1. duplicate local variable 2. type mismatch, can not convert string to boolean
16.
int dollars = 5;
System.out.println(dollars); // 5
float money;
float bigBucks = 99999.9; //error: type mismatch, can not convert double to fioat
money = dollars;
System.out.println(money); //5
dollars = bigBucks; //error: type mismatch, can not convert float to int
float literals should end with f or F letter. example- 99999.9f, by default all fraction values are double
17.
float quotient, dividend = 100.05f; (in qyestion f is missing, so throwing error)
int divisor = 5;
System.out.println(divisor);//5
quotient = dividend/divisor; // here divisor is of type int, but
// during calculation it will promoted to float
System.out.println(quotient); // 20.1
18.
float quotient, dividend = 100.05f;
int divisor = 5;
System.out.println(divisor);//5
quotient = dividend/(float)divisor; // here divisor is of type int, but
// we are explicitly casting to float value
System.out.println(quotient); // 20.1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.