1. 2. Indicate the errors, if any, in the following Java statements: a. int 5; b....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. 2. Indicate the errors, if any, in the following Java statements: a. int 5; b. int x-25; IX variable name is missing //variable name starts with # c. int age-20; // whitespace in variable name d. int hight 156; // OK e. float for 4.5; f. int 2rate=22; g. intz-22, y //for is keyword // variable name starts with a number 15, x; //OK Copy below code to your IDE and complete the following: public class Lab2 ( public static void main(String[] args) { //1. Declare and initialize a float variable. //2. Declare and initialize an integer variable. //3. Declare and initialize a long variable. /*4. Declare 3 integer variables, assign them different values, and calculate their sum. */ //5. Print all the previous variables (1-4) in a single line. //6. Print all the previous variables (1-4) in a separate line. //7. Declare a constant variable and assign a value to it. //8. Try to change the value of the constant that you have declared. //9. Declare a short variable and assign to it 86876. //10 change the values of question 1,2,3, and 4 to any value you like. //11 try to assign the variable in question 1 to the variable in question 2. Explain what happen. //12 Declare 3 variables in a single statement and assign to them values. 3. Write a code to calculate the average of two variables x and y and print the result. The average should be printed as a floating-point number. // write the skeleton of the java program. // declare and initialize two variables and name them x and y. You // should know how to declare a float variable to avoid any errors. // to calculate the average, you should know the formula // (average Total of amber) number of item in the st // change the above formula into java expression. // you may need to declare two or three more variables (sum, count // and average) // calculate and print the average result. 4. Write a whole program that calculate and output the sum of integers 2, 5, 24, 39. • ⚫ Challenging: 1. Write a java program that calculate below expression: 3 + 4x • You first need to change the expression into a java expression. ⚫ You start from left to right and write the numerator expression. Next, you add the division sign and write the denominator expression. 3+4x 3 + 4x 5 (3+4*x) 1(5) (3+4*x)/(5) // Declare and initialize all needed variables. // write the expression in a print statement. // change the value of x to 4 and print the result. ⚫ Challenging question: 2. Writing a numeric expression in Java involves a straightforward translation of an arithmetic expression using Java operators. For example, the arithmetic expression 10(y-5Xa+b+c) 1. 2. Indicate the errors, if any, in the following Java statements: a. int 5; b. int x-25; IX variable name is missing //variable name starts with # c. int age-20; // whitespace in variable name d. int hight 156; // OK e. float for 4.5; f. int 2rate=22; g. intz-22, y //for is keyword // variable name starts with a number 15, x; //OK Copy below code to your IDE and complete the following: public class Lab2 ( public static void main(String[] args) { //1. Declare and initialize a float variable. //2. Declare and initialize an integer variable. //3. Declare and initialize a long variable. /*4. Declare 3 integer variables, assign them different values, and calculate their sum. */ //5. Print all the previous variables (1-4) in a single line. //6. Print all the previous variables (1-4) in a separate line. //7. Declare a constant variable and assign a value to it. //8. Try to change the value of the constant that you have declared. //9. Declare a short variable and assign to it 86876. //10 change the values of question 1,2,3, and 4 to any value you like. //11 try to assign the variable in question 1 to the variable in question 2. Explain what happen. //12 Declare 3 variables in a single statement and assign to them values. 3. Write a code to calculate the average of two variables x and y and print the result. The average should be printed as a floating-point number. // write the skeleton of the java program. // declare and initialize two variables and name them x and y. You // should know how to declare a float variable to avoid any errors. // to calculate the average, you should know the formula // (average Total of amber) number of item in the st // change the above formula into java expression. // you may need to declare two or three more variables (sum, count // and average) // calculate and print the average result. 4. Write a whole program that calculate and output the sum of integers 2, 5, 24, 39. • ⚫ Challenging: 1. Write a java program that calculate below expression: 3 + 4x • You first need to change the expression into a java expression. ⚫ You start from left to right and write the numerator expression. Next, you add the division sign and write the denominator expression. 3+4x 3 + 4x 5 (3+4*x) 1(5) (3+4*x)/(5) // Declare and initialize all needed variables. // write the expression in a print statement. // change the value of x to 4 and print the result. ⚫ Challenging question: 2. Writing a numeric expression in Java involves a straightforward translation of an arithmetic expression using Java operators. For example, the arithmetic expression 10(y-5Xa+b+c)
Expert Answer:
Answer rating: 100% (QA)
java public class Lab2 public static void mainString args 1 Declare and initialize a float variable float floatValue 314f 2 Declare and initialize an ... View the full answer
Related Book For
Cambridge Checkpoint Lower Secondary Mathematics Student's Book 7
ISBN: 9781398301948
3rd Edition
Authors: Frankie Pimentel, Ric Pimentel, Terry Wall
Posted Date:
Students also viewed these programming questions
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Selected accounts of Holly Company are shown as follows. Instructions After analyzing the accounts, journalize (a) The July transactions (b) The adjusting entries that were made on July 31. Supplies...
-
The head of a hammer with a mass of 1.2 kg is allowed to fall onto a nail from a height of 0.50 m. What is the maximum amount of work it could do on the nail? Why do people not just "let it fall" but...
-
A convertible bond can be converted into ________. A. Preferred stock B. Common stock and then converted into preferred stock C. Common stock of a different company D. Common stock of the company
-
Plaintiff sought to enforce against the defendant estate a promise made by his now-deceased uncle to pay Plaintiff a sum of money if Plaintiff refrained from the use of alcohol and tobacco for a...
-
Mann Hardware has four employees who are paid on an hourly basis plus time-and-a-half for all hours worked in excess of 40 a week. Payroll data for the week ended March 15, 2014, are presented below....
-
Why are both ER Diagrams and Relational Modeling needed when a database system is developed?
-
Cherry Cotta makes custom ordered clay pots for residential gardens. Below is cost information regarding its latest job. a. Materials were purchased on account. $18,996 purchased b. A materials...
-
Referring to the digraph, schedule the tasks on two processors using the priority list T3, T5, T1, T 4 , T 2 T1 T2 2 T3 T4 Processor 1: 4 TS Referring to the digraph above, schedule the tasks on two...
-
A firm with annual revenues of $8,760,000 has DSO of 30 days. Calculate the change in receivables that would occur if the firm's collections deteriorated so that DSO increased to 50 days.
-
Students will be given 30 minutes for the following activity. Each student will use the Bingo sheet provided. Students will need to complete each square individually by writing their response to the...
-
Suppose you are the financial manager of a firm considering the following five projects (expand below to see the five projects). Five Projects Under Construction Five Projects Under Consideration...
-
With the help of HR and finance you were able to put together a nice project organization structure . As a Project Manager you have a decent understanding of The Tuckman Model of Team Development ....
-
A block of mass m = 3.23 kg on a frictionless plane inclined at angle 0 = 28.9 is connected by a cord over a massless, frictionless pulley to a second block of mass m2 = 2.39 kg hanging vertically...
-
A hydrogen atom, initially at rest, absorbs an ultraviolet photon with a wavelength of A = 154.3 nm. %3D Part A What is the atom's final speed if it now emits an identical photon in a direction that...
-
Revol Industries manufactures plastic bottles for the food industry. On average, Revol pays $76 per ton for its plastics. Revol's waste-disposal company has increased its waste-disposal charge to $57...
-
Using the formula P = 2l + 2b, calculate the perimeter of a rectangle if l = 3 cm and b = 5 cm. P = 2 3 + 2 5 P = 6 + 10 P = 16 cm
-
a. Derive a formula for converting the number of hours, h, into minutes, m. b. Use your formula to convert 4 1/2 hours to minutes.
-
A town in America has 2400 families and 4200 cars. What is the family : car ratio a. In its simplest form b. In the form 1 : n.
-
Which of the following best describes the underlying rationale for a written investment policy statement (IPS)? A. A written IPS communicates a plan for trying to achieve investment success. B. A...
-
Which of the following is least important as a reason for a written investment policy statement (IPS)? A. The IPS may be required by regulation. B. Having a written IPS is part of best practice for a...
-
Which of the following is least likely to be placed in the appendices to an investment policy statement (IPS)? A. Rebalancing Policy. B. Strategic Asset Allocation. C. Statement of Duties and...
Study smarter with the SolutionInn App