1
1. What does a compiler do?
a. Translates machine instructions to higher level languages
b. Translates programs written in a high level language into machine code.
c. Translates user programs to Java Programs
d. None of the above
2. Consider the following Java Program
public class VendingMachine
{ public static void main(String[] args)
{
System.out.println(“Please insert 25c”);
}
}
By what name would you save this program on your hard disk?
3. Give the output of the following program:
public class MethodExample
{ public static void main(String args[])
{ int y = 2, z = 1;
z = y * 2;
System.out.print(y + z);
}
}
4. Consider the following program:
public class Exam1
{
public static void main(String []args)
{
String str = new String("Arizona state university");
char ch1 = str.toLowerCase().toUpperCase().charAt(0);
char ch2 = str.toUpperCase().charAt(8);
char ch3 = str.toUpperCase().charAt(str.length()-1);
System.out.println("character 1 is:" + ch1);
System.out.println("character 2 is:" + ch2);
System.out.println("character 3 is:" + ch3);
}
}
What will be the output?
CSE 110 Practice Exam 1
Last Name_____________________ First Name ____________
2
5. Consider the program:
public class Exam1_1
{
public static void main(String []args)
{
int num1 = 4,num2 = 5;
System.out.println("4"+"5");
System.out.println(num1 + num2);
System.out.println("num1" + "num2");
System.out.println(4+5);
}
}
What will be the output?
6. Which of the following invokes the method length() of the object str and stores the result in