Programming Practice Problems


1)	Write a function that takes 2 integer parameters.
	The function should return the larger of the
	values.

2)	Declare an array that stores 100 doubles.
	

3)	Given:

	String name="George Mason University";
	int position=name.indexOf("son");	 
	int num_chars=name.length();

	What would the following statements print?
	System.out.println("The name contains "+num_chars+" characters.");
	System.out.println("The substring \"son\" begins at index: "+
	position+".");

4)	Write the code that reads in a line of text from the
	user and converts it to all upper case characters.

5)	Add comments to each line of code below:

	  int array[]={9,5,8,4,2}; int sum=0; double average;
          for(int count=0;count <array.length;count++)
                sum=sum+array[count];
          average=sum/array.length;
  	  System.out.print(average);

6)	What would be the graphics commands to set the
	background color to cyan and then create a pink
	rectangle in the upper left hand corner of the
	screen with a width of 50?

7)	Add the font commands necessary to write your
	name in a 32 point, bold font, under the rectangle.

Answers to 1-5
Answers to 6-7