Question: 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


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)
Step by Step Solution
3.42 Rating (149 Votes )
There are 3 Steps involved in it
There are multiple errors and issues in the provided statements Heres a breakdown of the errors a int5 Error Variable name is missing A valid variable name should start with a letter or underscore fol... View full answer
Get step-by-step solutions from verified subject matter experts
