Oop Exam

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Pangasinan State University

Lingayen, Pangasinan
Object-Oriented Programming
NAME: ______________________________
I.

The Java code block below aims to accept a persons name and
outputs the reversed String. Find ALL of the existing errors to correct
the program.
import java.util.*;
public class HelloWorld {
public static void main (String[] args)
{
Scanner console = new Scanner(system.in);
system.out.println("Enter your name:");
string name = Console.nextLine();
int name_length = name.length();
String output = "";
for (int num = 5; num < name_length; num++) {
Char x = name.charAt(num);
output = x + output;
for(int y = 0; y < num; y++){
System.out.print(" ");
}
system.out.print(name.charAt((name_length - 2) - num ));
system.out.println();
}
System.out.println("Reversed string: " + output1);
}
}

II.

Program Analysis

Question 1: What are the values of i,a, and b after the following code fragment runs.?
int i;
int a=1;
int b=0;
For(i = 0; i < 10; i++){
a = a * 2;
b++;
}

You might also like