System. Out. Print ("Enter An Integer:") A B C //this Program Performs A Simple Payroll Calculation
This document contains examples of Java code and questions about Java syntax and order of operations. It covers topics like variable declaration and assignment, arithmetic operators, comments, if/else statements, and evaluating expressions. Sample problems include writing code to display messages, assigning values to variables, identifying true/false statements, and determining the order of evaluation and final values for expressions.
System. Out. Print ("Enter An Integer:") A B C //this Program Performs A Simple Payroll Calculation
This document contains examples of Java code and questions about Java syntax and order of operations. It covers topics like variable declaration and assignment, arithmetic operators, comments, if/else statements, and evaluating expressions. Sample problems include writing code to display messages, assigning values to variables, identifying true/false statements, and determining the order of evaluation and final values for expressions.
7 Fill in the blanks in each of the following statements:
a) Comments are used to document a program and improve its readability. b) A decision can be made in a Java program with an if statement. c) Calculations are normally performed by assignment statements. d) The arithmetic operators with the same precedence as multiplication are remainder and division. e) When parentheses in an arithmetic expression are nested, the innermost set of parentheses is evaluated first. f) A location in the computer’s memory that may contain different values at various times throughout the execution of a program is called a variable. 2.8 Write Java statements that accomplish each of the following tasks: a. Display the message "Enter an integer: ", leaving the cursor on the same line System. out. Print (“enter an integer:”); b. Assign the product of variables b and c to variable a. ➢ a=b*c; c. Use a comment to state that a program performs a sample payroll calculation. //this program performs a simple payroll calculation. 2.9 State whether each of the following is true or false. If false, explain why. a) Java operators are evaluated from left to right. False b) The following are all valid variable names: _under_bar_, m928134, t5, j7, her_sales$, his_$account_total, a, b$, c, z and z2. True. c) A valid Java arithmetic expression with no parentheses is evaluated from left to right. False d) The following are all invalid variable names: 3g, 87, 67h2, h22 and 2h. false 2.10 Assuming that x = 2 and y = 3, what does each of the following statements display? a) System.out.printf ("x = %d%n", x); x=2 b) System.out.printf("Value of %d + %d is %d%n", x, x, (x + x)); Value of 2 + 2 is 4 c) System.out.printf("x ="); x= d) System.out.printf("%d = %d%n", (x + y), (y + x)); 5=5 2.11 Which of the following Java statements contain variables whose values are modified? a) p = i + j + k + 7; b) System.out.println("variables whose values are modified"); c) System.out.println("a = 5"); d) value = input.nextInt(); answer: a, d. 2.12 Given that y = ax3 + 7, which of the following are correct Java statements for this equation? a) y = a * x * x * x + 7; b) y = a * x * x * (x + 7); c) y = (a * x) * x * (x + 7); d) y = (a * x) * x * x + 7; e) y = a * (x * x * x) + 7; f) y = a * x * (x * x + 7); answer: a, d, e. 2.13 State the order of evaluation of the operators in each of the following Java statements, and show the value of x after each statement is performed: a) x = 7 + 3 * 6 / 2 - 1; b) x = 2 % 2 + 2 * 2 - 2 / 2; c) x = (3 * 9 * (3 + (9 * 3 / (3))));