Review Problems for CS 125 Exam 1

These are review problems for the exam on March 10. The problems on the in class exam will be very similar. The exam covers Maple, and Chapter 2 of the Java textbook. Try to do these problems without the use of Maple or Java, since you will have to do the in class exam without them.
You can print these problems out by using the "File -> Print..." menu of Netscape.

Problem 1:
How many different values could the following expression take on if parentheses are added?
2*3+4/2

Problem 2:
In Maple, if Digits:=3; then what are the results of the following commands?
> 1010 + 3;
> 1010 + 3.0;
> 51.3 + 1.05;

Problem 3:
In Java, what is the result of the following two lines?
        String s = "why java?";
        print( s.substring(0, s.length()));

Problem 4:
Part (a): In Java, what is the value of y if
         y = "2+2" + 2;

Part (b): In Maple, what is the value of y if

> y := `2+2` + 2; # Those are left-quotes.

Problem 5:
In Maple, if x is a list, describe what the following command does, and how it does it.
> x := [ seq( op(i,x), i=2 .. nops(x) ), op(1,x) ];

Problem 6:
In Maple, what is the output of the following two commands?
> x := [ 1, [2, 3, 4], [5, [6,7]], 8, [9]]:
> op(2, op(3,x));

Problem 7:
In Maple, what is the output for each of the following command?
> nops( [1, 2, [3, [4, 5]], 6, [7]] );
> nops( x^2-3*x+2 );

Problem 8:
In Maple, enter the commands
> x := 2: y := 3:
> z := 'x' + y: # Those are right-quotes.
> x := 4:
> z;

What is the output from the last command?

Problem 9:
In Java, find three syntax errors in the following program.

       public class Incorrect
       {public static void main(String[] args)
         { x = 3;
           System.out.println("the value of x is" x),
           System.out.println("is that OK?);
        }

Problem 10:
In Maple, what is the output of the following command?
> seq( seq( i+j, i=1..2), j=3..4);

Problem 11:
In Java, if x is an integer, and I wish to convert it to a string, what is wrong with the following line?
          x = "" + x;


Return to the main Maple page.
Return to the main Java page.
Return to the CS 125 home page.


compliments and criticisms