SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

Similar documents
Programming with Java

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

JAVA OPERATORS GENERAL

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

McGill University School of Computer Science COMP-202A Introduction to Computing 1

EXAMINATION FOR THE BSC (HONS) INFORMATION SYSTEMS; BSC (HONS) INFORMATION TECHNOLOGY & BSC (HONS) COMPUTER SCIENCE; YEAR 1

Operators in java Operator operands.

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Chapter 4: Control structures. Repetition

Chapter 4: Control structures

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Example: Monte Carlo Simulation 1

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Instructor: Eng.Omar Al-Nahal

Object-Oriented Programming

3. Java - Language Constructs I

CMPT 125: Lecture 3 Data and Expressions

Getting started with Java

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

1. An operation in which an overall value is computed incrementally, often using a loop.

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Loops. CSE 114, Computer Science 1 Stony Brook University

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Technical Questions. Q 1) What are the key features in C programming language?

Object Oriented Programming Lecture (2.1) Supervisor Ebtsam AbdelHakam Department of Computer Science Najran University

Logical Operators and switch

Decisions in Java IF Statements

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Unit 3. Operators. School of Science and Technology INTRODUCTION

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

Comp 170 Test 1 SAMPLE June 8, 2000

INFO Object-Oriented Programming

Prof. Navrati Saxena TA: Rochak Sachan

Introduction to Object-Oriented Programming

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Simple Java Reference

1 Lexical Considerations

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Multiple-Subscripted Arrays

Midterm Examination (MTA)

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Java Identifiers, Data Types & Variables

Chapter 3. Selections

ECE 122. Engineering Problem Solving with Java

Introduction to the Java Basics: Control Flow Statements

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Lecture Set 4: More About Methods and More About Operators

Loops and Expression Types

BASIC ELEMENTS OF A COMPUTER PROGRAM

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Example. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.

Chapter 2: Using Data

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Constants and Variables

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Java is an objet-oriented programming language providing features that support

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

CSC 1214: Object-Oriented Programming

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

COMP Primitive and Class Types. Yi Hong May 14, 2015

Recap: Assignment as an Operator CS 112 Introduction to Programming

STUDENT LESSON A12 Iterations

Java Programming Language. 0 A history

CSEN 202 Introduction to Computer Programming

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

Software and Programming 1

Operators and Expressions

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

More Programming Constructs -- Introduction

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Loops. Repeat after me

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

CS 112 Introduction to Programming

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

B.V. Patel Institute of BMC & IT, UTU 2014

BSc (Hons) Computer Science with Network Security/ BSc (Hons) Software Engineering/ BSc (Hons) Web Technologies. Examinations for 2016 Semester 1

Operators & Expressions

INDIAN SCHOOL SOHAR FIRST TERM EXAM ( ) INFORMATICS PRACTICES

Transcription:

FACULTY OF SCIENCE AND TECHNOLOGY SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1 ACADEMIC SESSION 2014; SEMESTER 3 PRG102D: BASIC PROGRAMMING CONCEPTS

Section A Compulsory section Question 1 (50 marks) a) Figure 1 Figure 1 shows the Java environment. Answer the following: i) What is the output of Java compiler? ii) What is X and Y? iii) What does X do? iv) Explain ONE benefit of writing a program using Java. (1 mark) (2 marks) (2 marks) (2 marks) b) Copy Table 1 to your answer booklet. Choose the best data types for each of the following so that no memory storage is wasted. Give an example of a typical value that would be held by the variable. Justify your choice. (15 marks) No. Item name Data type i) Car license plate ii) Car registration year iii) Car price iv) Car speed v) Car color Table 1 Justification for choosing the data type Item value 1

c) Identify THREE flaws in the following while statement. Explain how the flaws occur and provide a solution. (6 marks) public class flawedprogram { public static void main(string[] args) { int z = 0; int sum = 0; while (z >= 0) { sum += z; System.out.println(sum); d) What is the output from the following segment of code? (6 marks) public class DisplayObjects { public static void printobj(){ int a = 5; for (int i=1; i<=a;i++ ){ for (int j=5; j>=i;j-- ){ System.out.print("o"); System.out.println(""); public static void main(string[] args) { for (int cnt=1; cnt<3; cnt++){ printobj(); e) Determine whether each of the following is true or false. If false, please provide a reason or an explanation. (10 marks) i) The statement int[ ] idnum=new int[35]; reserves enough memory for exactly 34 integers. ii) When you create a StringBuilder object with an initial value of June, its capacity is 16. iii) You can improve loop performance when two conditions must both be true by testing for the most likely occurrence first. iv) The value of any false operation becomes true when preceded by the NOT operator. v) The statement if(fees <5.00 && fee >20.00) can be used to select fee values that are higher or lower than the specified limits. 2

f) Rewrite the following for statements as while statements, and provide the output. (6 marks) int sum; for (int i = 0; i < 5; i ++) { sum = 0; for (int j = 0; j <= i; j++) sum = sum + j; System.out.println(sum); 3

Section B Answer any TWO questions from this section. Question 2 (25 marks) a) Choose a word from the following box to complete the sentence. Write your answer in the answer booklet. (10 marks) decision nested float subscript reference precedence unary nested new while A(n) i) structure involves choosing between alternative courses of action based on some value within a program. A(n) ii) data type can hold floating-point values of up to six or seven significant digits of accuracy. When you combine mathematical operations in a single statement, you must understand operator iii), or the rules for the order in which parts of a mathematical expression are evaluated. A(n) iv) is an integer contained within square brackets that indicates one of an array s variables, or elements. As an object, a String variable name is not a simple data type. It is a(n) v) ; that is, a variable that holds a memory address. The prefix and postfix increment operators are vi) operators because you use them with one value. When loops are vii), each pair contains an inner loop and an outer loop. An inside block is viii), or contained entirely within, the outside block. To allocate the needed memory for a class object, you must use the ix) operator. A(n) x) loop is one in which the loop-controlling Boolean expression is the first statement in the loop. b) Write separate partial Java codes for each of the following tasks using an integer array mark of size 20: (15 marks) i) Get 20 integer data from user. (3 marks) ii) Find the highest and lowest value. (6 marks) iii) Count the number of negative and positive values. (6 marks) 4

Question 3 (25 marks) a) Complete the following sentences. Write your answers in the answer booklet. (9 marks) i), and display information in the command window. ii) iii) All programs can be written in terms of three types of control structures:,, and. The operator can be used to ensure that two conditions are both true before choosing a certain path of execution. iv) An array is a group of (called elements or components) containing values that all have the same. b) What does the following program print? (7 marks) 5

c) The following code has some syntactic and/semantic errors. The expected output has also been provided below. Analyze the given output and determine the problems. Fix it by re-writing the entire code. (9 marks) // Print every character between Unicode 65 and 122 // Start new line after 20 characters public class DebugQ3c { public static void main(string args[]) { char letter; int a; final int MIN = 65; final int MAX = 122; final int STOPLINE1 = 85; final int STOPLINE2 =!)%; for(a = MMAX; a <= MIN; a++) { letter = (char)a; System.out.print(" " + letter); if((a == STOPLINE) (a == STOPLINE2)) System.out.println(); System.out.println("\nEnd of application"); Expected output: 6

Question 4 (25 marks) a) Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. The expected output is as follows: (13 marks) Part (a): 1 2 3 4 Part (b): 1 2 3 4 Part (c): 1 2 3 4 Note that your expected output must use the following statements: Part (a): 1 2 3 4 use one System.out.println statement Part (b): 1 2 3 4 - use four System.out.print statements Part (c): 1 2 3 4 - use one System.out.printf statement b) Convert below pseudo code into Java statements enclosed by main method. (12 marks) Process_Input Display message Enter 1, 2, or 3, or 4 to Exit Get number from user while (number!= 4) If (number equal 1 or number equal 2 or number equal 3) Display message Good Job Else Display message You should enter 1,2,3, or 4 Display message Enter 1, 2, or 3, or 4 to Exit Get number from user EndWhile END ~ END OF PAPER ~ 7