# The simplified expression should not contain either

• Notes
• UltraLightningCobra8457
• 7

This preview shows page 5 - 7 out of 7 pages.

Use DeMorgan's Law to help simplify the following expression. The simplified expression should not contain either of the symbols ! or != !(!(x > 42) && !(x <13)) x>42 || x<13 (3 marks)

Subscribe to view the full document.

(c) Complete the truth table for the following boolean expression P && Q || !(P || Q) && P P Q P&&Q P||Q !(P||Q) !(P||Q)&&P P&&Q || !(P||Q)&&P T T T T F F T T F F T F F F F T F T F F F F F F F T F F (4 marks) Question 7 (10 marks) (a) Translate the following sentences from English to Java (i) If a is less than 7 or b is greater than 7 then print out " greater than 7 " if( a<7 || b>7) System.out.println("greater than 7"); (1 mark) (ii) Print " too easy " unless finalMark is less than 50 if( !(finalMark < 50) ) System.out.println("too easy"); (1 mark) (iii) Print " too hard ", but only if finalMark is less than 50 if( finalMark < 50 ) System.out.println("too hard"); (1 mark) (iv) If either a or b is greater than 8 and if neither c nor d is less than 8, then print " abcd " if( (a > 8 || b > 8) && !(c<8 || d<8) ) System.out.println("abcd"); (2 marks) (b) What is the output of the following code? int x = 4; int y = 5; int z = 6; if(x>y || y>z) x = 0; else if(x<y && y<z) if(x==y) z=y; else y = 0; else if(y==0 || x<z) z = 0; System.out.println(x + " " + y + " " + z); 4 0 6 (5 marks) Question 8 (5 marks) Assume that variables r and s have been declared as follows: Rectangle r = new Rectangle(10,20,30,40); Rectangle s = new Rectangle(10,20,30,40); (i) Write an if statement which will print out " equal value " if r is equal in value to s . if ( r.equals(s) ) System.out.println("equal value"); (2 marks) (ii) Write an if statement which prints out " equal reference " if r is equal in reference to s . if ( r==s ) System.out.println("equal reference"); (2 marks) (iii) Are the two variables r and s equal in reference, equal in value, or both? equal in value (1 mark)
Question 9 (5 marks) What is the output of the following code? int x = 25; int y = 10; int count = x; System.out.println("Before: " + count); while(count > y){ if(count%5==0) System.out.println(count); count--; } System.out.println("After: " + count); Before: 25 25 20 15 After: 10 (5 marks)
You've reached the end of this preview.
• Summer '12
• System.out.println, FruitProfile

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern