Initial Value - Computer Science - Quiz, Exercises of Computer Science

Main points of this past exam are: Initial Value, Equivalent Java Expression, Unix Command, Java Program, Code Fragment, Operators are Used, Produced by Evaluating

Typology: Exercises

2012/2013

Uploaded on 04/07/2013

shabi_564
shabi_564 🇮🇳

4.5

(13)

188 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Signature _____________________ CSE 11 Name ________________________
Quiz 2
cs11f ____ Fall 2010 Student ID ____________________
This quiz is to be taken by yourself with closed books, closed notes, no calculators.
(Partial) Operator Precedence Table
Operators Associativity
* / % left to right
+ - left to right
< <= > >= left to right
== != left to right
&& left to right
|| left to right
= right to left
1) What are the values of x and y (left) and a and b (right) after the following code segments are executed?
2) What is the equivalent Java expression for the following expression such that no ! operators are used?
!( a > 5 && b != -9 ) ____________________________________________
3) Assume we have a Java source file named Program.java and it uses at least one class in the objectdraw
library.
Write the full Unix command to compile this Java program.
________________________________________________________________________
This command will produce a file named:
________________________________________________________________________
Write the full Unix command to run this as a Java application.
________________________________________________________________________
Assume we have correctly written a Program.html file. Write the full Unix command to run the above program
as an applet.
________________________________________________________________________
x =
y =
int x = 2, y = 4;
if ( x++ >= 3 || --y >= 3 )
x = x++ + --y;
else
x = ++x + y--;
a =
b =
int a = 2, b = 4;
if ( a++ >= 3 && --b >= 3 )
a = a++ + --b;
else
a = ++a + b--;
pf2

Partial preview of the text

Download Initial Value - Computer Science - Quiz and more Exercises Computer Science in PDF only on Docsity!

Signature _____________________ CSE 11 Name ________________________

Quiz 2

cs11f ____ Fall 2010 Student ID ____________________

This quiz is to be taken by yourself with closed books, closed notes, no calculators. (Partial) Operator Precedence Table Operators Associativity

  • / % left to right
    • left to right < <= > >= left to right == != left to right && left to right || left to right = right to left
  1. What are the values of x and y (left) and a and b (right) after the following code segments are executed?

  2. What is the equivalent Java expression for the following expression such that no! operators are used?

!( a > 5 && b != -9 ) ____________________________________________

  1. Assume we have a Java source file named Program.java and it uses at least one class in the objectdraw library.

Write the full Unix command to compile this Java program.


This command will produce a file named:


Write the full Unix command to run this as a Java application.


Assume we have correctly written a Program.html file. Write the full Unix command to run the above program as an applet.


x = y =

int x = 2, y = 4;

if ( x++ >= 3 || --y >= 3 ) x = x++ + --y; else x = ++x + y--;

a = b =

int a = 2, b = 4;

if ( a++ >= 3 && --b >= 3 ) a = a++ + --b; else a = ++a + b--;

  1. Assume a program had the following declarations:

Location loc1 = new Location( 42, 420 ); Location loc2 = loc1; Location loc3 = new Location( loc2 );

What results would be produced by evaluating the following expressions?

( loc1 == loc2 ) ____________ loc1.equals( loc3 ) ____________

( loc2 == loc3 ) ____________ loc3.equals( new Location( loc2 ) ) ____________

  1. What output is produced with the following code fragment? Assume method1() is invoked as

Quiz2 q2 = new Quiz2(); q2.method1( 17 );

public class Quiz { private int a; // Line 3

public void method1( int x ) { int a; // Line 7 int b = x;

a = b % 5; this.a = b / 3;

System.out.println( "a = " + a ); System.out.println( "b = " + b ); System.out.println( "this.a = " + this.a ); System.out.println( "method2() result = " + method2( x ) ); System.out.println( "this.a = " + this.a ); }

private int method2( int x ) { int a = x; int b = this.a;

b = b * 2;

System.out.println( "a = " + a ); System.out.println( "b = " + b ); System.out.println( "this.a = " + this.a );

this.a = b + 2;

return a + 2; } }

What is the initial value of a on Line 3? ___________

What is the initial value of a on Line 7? ___________

Output: a = __________ b = __________ this.a = __________ a = __________ b = __________ this.a = __________ method2() result = __________ this.a = __________