




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Figure 115: A program coded to run five iterations of statements using a while loop ............................................................................................... Figure 116: A program that keeps prompting for input .......................... Figure 117: A program used to find the average of numbers.................. Figure 118: A guessing game program....................................................... Figure 119: A flowchart representing a for statement .............................. Figure 120: A program calculating the average of input data where the number of data point can be determined via keyboard ................... Figure 121: A program that finds prime factors of an input integer ...... Figure 122: A program calculating term values in a first-order recurrence relation .................................................................................................... Figure 123: Demonstration of using the break statement ........................ Figure 124: Demonstration of using the continue statement which allows the program to ignore statements in some certain iteration............ Figure 125: An example of nested loops in action .................................... Figure 126: Another example of nested loops in action ........................... Figure 127: A compilation error caused by that a variable being declared inside a for loop is used outside .......................................................... Figure 128: Another example of error caused by a variable’s scope ...... Figure 129: A program finding all possible solutions to a 2 +b^2 +c^2 =200 .. Figure 130: Two vectors in the Cartesian coordinate................................ Figure 131: A flowchart showing various subroutines used in the VectorAngle program ........................................................................... Figure 132: A program finding the angle between two vectors.............. Figure 133: Compilation error due to usage of a variable declared inside a method outside the method .............................................................. Figure 134: Illustration of variables when f() is invoked(Step1) ............. Figure 135: Illustration of variables when f() is invoked (Step2) ............ Figure 136: Illustration of variables when f() is invoked (Step3) ............ Figure 137: Illustration of variables when f() is invoked (Step4) ............ Figure 138: A program demonstrating variable name re-use.................. Figure 139: A program that swaps values of two variables..................... Figure 140: An incorrect implementation of a method that swaps values of its two input argument..................................................................... Figure 141: A program demonstrating method overloading .................. Figure 142: A program demonstrating method overloading including a case where the input argument list is not entirely matched with any overloaded methods..............................................................................
Figure 157: An example of performing the selection sort on an array.
List of Tables
Table 1: Values of 2 n^ ........................................................................................ Table 2: Powers of two and their abbreviation............................................ Table 3: Escape sequences .............................................................................. Table 4: Primitive data types in Java............................................................. Table 5: Some examples of characters with their corresponding unicode encodings .................................................................................................. Table 6: Description of logic operators ......................................................... Table 7: Precedence and associativity of some basic operators................. Table 8: Data type conversion table .............................................................. Table 9: Data types from expression evaluation ......................................... Table 10: FunnyEncoder encoding scheme................................................ Table 11: Examples of real-world objects together with their attributes and behaviors ......................................................................................... Table 12: Summary of access levels (packages are ignored)....................
Chapter 1: Introduction to
Computer Systems
Readers should Be familiar with computer components and understand their main functionalities. Conceptually understand how data are represented in computers. Be able to conceptually explain how to solve problems using computers.
Hello Computer, my dear friend!
A computer is a machine capable of automatically processing data according to instruction lists given. Data processing includes, but not limited to, carrying out arithmetic operations, comparing logical values, as well as, transmitting, receiving and storing information. Data processing tasks, no matter how long or complex they are, can be performed with series of some simple commands, considered “native” to the computers processing those data.
From day one until now, the so-called “native” commands are done electronically in most computers. Many benefits we gain by using computers as our tools to problem solving are due to the fact that electronic devices can perform these commands in a very fast and reliable fashion. Here are some examples of such benefits in normal circumstances.
Computers work fast. Despite common complaints that sounds like “My computer is slow”, it does work very fast! A computer can execute billions commands in a second. Suppose we have golf balls that each of them can be either white or black, how fast can you compare the colors of one thousand pairs of golf balls and say how many pairs are different? A computer can do it in one nanosecond.