1
Name:_______________________
Covers Chapters 4-5 SAMPLE
CSCI 1301 Introduction to Programming
Armstrong Atlantic State University
Instructor: Dr. Y. Daniel Liang
I pledge by honor that I will not discuss this exam with anyone until my
instructor reviews the exam in the class. Signed by ___________________.
Part I.
(a) (3 pts) If you enter input 9, show the output of the following code:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print(“Enter an integer: “);
int number = input.nextInt();
int i;
(b) (2 pts) Show the output of the following code:
public class Test {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.print((i + 4) +);
}
}
}
2
(c) (4 pts) show the output of the following code:
public class Test {
public static void main(String[] args) {
int i = 1;
Part II: (10 pts each):
1. Write a loop that computes (No need to write a complete program)
100
1
99
2
98
3
4
97
3
98
2
99
1
100 ++++++
3
2. Write a program that counts the number of lowercase letters in a
string. Your program should prompt the user to enter the string and
display the count.
4
Part III: Multiple Choice Questions: (1 pts each)
(1. Mark your answers on the sheet. 2. Go to LiveLab
(tiger.armstrong.edu/JavaLiveLab), login, and click Take