Question: Homework 2 java language (6 x 3 = 18 points) Q1. Write statements to accomplish each of the following: 1. Test and state whether variable

 Homework 2 java language (6 x 3 = 18 points) Q1.Write statements to accomplish each of the following: 1. Test and state

Homework 2 java language (6 x 3 = 18 points) Q1. Write statements to accomplish each of the following: 1. Test and state whether variable number is positive or negative. 2. Test whether variable number is positive. If it is, test if its is less than 10. if it is, print "The number is positive and less than 10". 3. Test whether variable x is less than or equal 50. If it is, print x is less than or equal 50". Q2. Identify and correct the errors in each of the following code: (8 x 4 = 32 points) 1. class test{ 2. public class test public static void main(String[] argv){ public static void main(String[] argv) { if ( x = 10 ) if (x == 10) System.out.println("x = 10"); System.out.println("x = 10" ); } else if } System.out.println("x * 10"); }} 3. public class test public static void main(String[] argv) { if ( x == 10 ) System.out.println("x = 10" ); System.out.println("Good bye" ); else System.out.println("x #10"); }} 4. public class test public static void main(String[] args) { if (x == 10); System.out.println("x = 10"); else System.out.println("x 10" ); }} Q3. Evaluate the following expression. Show each step? (2 x 10 = 20 points) 1. Given: int i = 1, j = 2, k = 3, m = 4; evaluate: j *= k = m + 5 2. Given: int a =1, b =2,c=3, d =4; evaluate: ++b /c+a* d++; what are the new values of a, b, c, and d? Q4. Re-write the equivalent statements for each of the following: (2 x 15 = 30 points) 1. Use switch statement (hint: use logical operators) 1. char ch = input.charAt(i); switch(ch) { case'+': case': gotoper(ch, 1); break; case: 2. Use conditional operators (i.e.?:) 2. if (age > 18) accessAllowed = true; else accessAllowed = false; case '/: gotOper(ch, 2); break; case '': theStack.push(ch); break; case '); gotParen(ch); break; default: output = output + ch; } 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!