Code Line,User Explanation,Line-Explanation in PCEX,Annotation Score "int [] arr = { 1, 2, 3};",Declares the array we want to use for our assignment,We initialize the array of type int to hold the specified numbers.,4 "int [] arr = { 1, 2, 3};",Declares the array we want to use for our assignment,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,3 for ( int i = 0; i < arr.length; i++ ) {,This line assures that we loop over all the elements in the array we want to increment,We want to iterate over the array and increment each element in the array by 1.,4 for ( int i = 0; i < arr.length; i++ ) {,This line assures that we loop over all the elements in the array we want to increment,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,This line assures that we loop over all the elements in the array we want to increment,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,1 arr[i] += 1;,extracts to value at the i-th index of the array and adds 1 to that value.,This statement increments the element at the index i of the array by 1.,4 arr[i] += 1;,then it stores that value back in the array at the i-th index,This statement increments the element at the index i of the array by 1.,2 int num = 15;,variable decleration: declares the number we are trying to divide,We define variable num to store the number that we want to find its smallest divisor.,4 int num = 15;,variable decleration: declares the number we are trying to divide,We could initialize it to any positive integer greater than 1.,1 int num = 15;,variable decleration: declares the number we are trying to divide,"In this program, we initialize variable num to 15.",2 int divisor = 2;,variable decleration. Declares the start point of where we want to test from,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,variable decleration. Declares the start point of where we want to test from,We define variable divisor to store the smallest divisor of the number.,2 divisor += 1;,"if the loop condition is true, then we increment the divisor by 1","When the divisor is not a factor of the number, we increment the variable divisor by 1.",3 while (num % divisor != 0) {,checks if the module of the expression is not equal to 0 and will loop until the condition is true.,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,checks if the module of the expression is not equal to 0 and will loop until the condition is true.,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,2 while (num % divisor != 0) {,checks if the module of the expression is not equal to 0 and will loop until the condition is true.,"Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,checks if the module of the expression is not equal to 0 and will loop until the condition is true.,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",3 while (num % divisor != 0) {,checks if the module of the expression is not equal to 0 and will loop until the condition is true.,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,3 while (num % divisor != 0) {,"if it is not 0, the condition is true which causes the loop to go","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",1 while (num % divisor != 0) {,"if it is not 0, the condition is true which causes the loop to go",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,"if it is not 0, the condition is true which causes the loop to go","Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,"if it is not 0, the condition is true which causes the loop to go","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,"if it is not 0, the condition is true which causes the loop to go",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",prints to the consol for the user to see what the smallest divisor was of the number,This statement prints to the default standard output stream the smallest divisor of the number.,4 "int [] arr = { 1, 2, 3};",create java array list with all the elements are integers,We initialize the array of type int to hold the specified numbers.,3 "int [] arr = { 1, 2, 3};",create java array list with all the elements are integers,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,iterate all elements in the array,We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,iterate all elements in the array,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,iterate all elements in the array,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,2 arr[i] += 1;,Add 1 to i.,This statement increments the element at the index i of the array by 1.,1 arr[i] += 1;,Each iteration will add 1 to the next element in the array.,This statement increments the element at the index i of the array by 1.,3 int num = 15;,"declare a integer called num, and assign it's value with 15",We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,"declare a integer called num, and assign it's value with 15",We could initialize it to any positive integer greater than 1.,2 int num = 15;,"declare a integer called num, and assign it's value with 15","In this program, we initialize variable num to 15.",5 int divisor = 2;,"declare an integer named divisor, assign it's value to 2.",We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,4 int divisor = 2;,"declare an integer named divisor, assign it's value to 2.",We define variable divisor to store the smallest divisor of the number.,3 while (num % divisor != 0) {,write a loop.,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,write a loop.,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,write a loop.,"Therefore, we need to use a loop structure.",5 while (num % divisor != 0) {,write a loop.,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,write a loop.,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,1 while (num % divisor != 0) {,"the condition is ""if the remainder of number divided by divisor is not zero"", then enter the loop","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",1 while (num % divisor != 0) {,"the condition is ""if the remainder of number divided by divisor is not zero"", then enter the loop",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,2 while (num % divisor != 0) {,"the condition is ""if the remainder of number divided by divisor is not zero"", then enter the loop","Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,"the condition is ""if the remainder of number divided by divisor is not zero"", then enter the loop","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",3 while (num % divisor != 0) {,"the condition is ""if the remainder of number divided by divisor is not zero"", then enter the loop",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 divisor += 1;,add 1 to divisor,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",4 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);","print the ""The smallest divisor of the num(what) is divisor(what).",This statement prints to the default standard output stream the smallest divisor of the number.,4 int num = 1234;,Initialize a number to some value.,We need variable num to store the integer that we want to print its digits.,3 do {,Start the loop where the digits are printed.,We need to process the digits of the integer from right to left and print them.,3 do {,Start the loop where the digits are printed.,"Therefore, we need to use a loop structure.",3 do {,Start the loop where the digits are printed.,"In this program, we do this by using a do loop.",3 do {,Start the loop where the digits are printed.,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,2 System.out.println(num % 10);,Print the rightmost digit of the current value of num.,Each printed digit is followed by the line separator (e.g. '\n') at the end.,2 System.out.println(num % 10);,Print the rightmost digit of the current value of num.,We need to extract the last digit in the 1's position of the integer.,4 System.out.println(num % 10);,Print the rightmost digit of the current value of num.,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",1 System.out.println(num % 10);,Print the rightmost digit of the current value of num.,We do this by calculating the remainder of the division of the integer by 10.,2 System.out.println(num % 10);,Print the rightmost digit of the current value of num.,"Then, this statement prints the last digit of the integer to the standard output stream.",4 num = num / 10;,Divide num by 10 to remove the rightmost digit.,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",3 num = num / 10;,Divide num by 10 to remove the rightmost digit.,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,4 num = num / 10;,Divide num by 10 to remove the rightmost digit.,Note that this statement performs an integer division because both operand of the / operator are integer.,1 } while (num > 0);,Continue the loop until all of the digits have been printed.,We need to check for termination conditions to avoid infinite loops.,3 } while (num > 0);,Continue the loop until all of the digits have been printed.,The loop should terminate when we run out of digits to process.,4 } while (num > 0);,Continue the loop until all of the digits have been printed.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",3 } while (num > 0);,Continue the loop until all of the digits have been printed.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",3 } while (num > 0);,Continue the loop until all of the digits have been printed.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,4 Scanner scan = new Scanner(System.in);,Create a scanner to get input from the user.,"To read the input values from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,Create a scanner to get input from the user.,We need to read and process the values that the user enters.,3 "System.out.println(""Enter the phone age in years:"");",Ask the user to enter the phone age.,We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,Get the phone age that the user entered.,We read the phone age by calling the nextInt() method because this input is an integer.,3 int phoneAge = scan.nextInt();,Get the phone age that the user entered.,We need to read the phone age that the user enters and store it in a variable.,3 "System.out.println(""Enter whether the phone is broken (true or false):"");",Ask the user if the phone is broken.,We prompt the user to enter whether the phone is broken.,4 boolean isBroken = scan.nextBoolean();,Check whether the user entered true or false to the previous question.,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,Check whether the user entered true or false to the previous question.,"The variable isBroken is true when the phone is broken, and false otherwise.",3 boolean isBroken = scan.nextBoolean();,Check whether the user entered true or false to the previous question.,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,3 scan.close();,Close the scanner since it is not needed any more.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 boolean needPhone = isBroken || phoneAge >= 3;,Check if the phone is broken or its age is greater than or equal to 3.,We use the || operator (called or) to combine the two conditions.,3 boolean needPhone = isBroken || phoneAge >= 3;,Check if the phone is broken or its age is greater than or equal to 3.,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,4 boolean needPhone = isBroken || phoneAge >= 3;,Check if the phone is broken or its age is greater than or equal to 3.,We need two conditions to determine if it is the time for a new phone.,2 System.out.println(needPhone);,Print out whether a new phone is needed.,This statement prints true/false depending on whether it is time to buy a new phone.,4 System.out.println(needPhone);,Print out whether a new phone is needed.,The printed value is followed by an end-of-line character in the end.,2 Scanner scan = new Scanner(System.in);,Create a new scanner to get the user's input.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,Create a new scanner to get the user's input.,We need to read and process the value that the user enters.,3 "System.out.println(""Enter an integer for seconds: "");",Ask the user to enter the number of seconds.,We prompt the user to enter the seconds.,5 int seconds = scan.nextInt();,Get the number entered by the user.,We need to read the seconds that the user enters and store it in a variable.,3 int seconds = scan.nextInt();,Get the number entered by the user.,We read the seconds by calling the nextInt() method because this input is an integer.,2 scan.close();,Close the scanner since it is not needed any more.,We close the scanner as we do not want to process any input from the user in the rest of the program.,4 int minutes = seconds / 60;,Get the minutes by dividing the seconds by 60.,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",4 int minutes = seconds / 60;,Get the minutes by dividing the seconds by 60.,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,Get the remaining seconds by calculating seconds modulo 60.,This is because there are 60 seconds in a minute.,2 int remainingSeconds = seconds % 60;,Get the remaining seconds by calculating seconds modulo 60.,Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,Get the remaining seconds by calculating seconds modulo 60.,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");","Print out the seconds, minutes, and remaining seconds.",This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,4 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");","Print out the seconds, minutes, and remaining seconds.",The printed text is followed by the end-of-line character at the end.,2 int num = 15;,Initialize num to some number.,We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,Initialize num to some number.,We could initialize it to any positive integer greater than 1.,3 int num = 15;,Initialize num to some number.,"In this program, we initialize variable num to 15.",3 int divisor = 2;,Initialize divisor to 2 for use in the while loop.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,Initialize divisor to 2 for use in the while loop.,We define variable divisor to store the smallest divisor of the number.,2 while (num % divisor != 0) {,Loop until a divisor is found.,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",3 while (num % divisor != 0) {,Loop until a divisor is found.,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,2 while (num % divisor != 0) {,Loop until a divisor is found.,"Therefore, we need to use a loop structure.",4 while (num % divisor != 0) {,Loop until a divisor is found.,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",3 while (num % divisor != 0) {,Loop until a divisor is found.,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,1 divisor += 1;,Increment divisor by 1 to check if the next number is a divisor.,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",3 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",Print out the number and its smallest divisor.,This statement prints to the default standard output stream the smallest divisor of the number.,4 Scanner scan = new Scanner(System.in);,Make a new scanner to get input from the user.,"To read the input value from the user, we need to define a Scanner object.",5 Scanner scan = new Scanner(System.in);,Make a new scanner to get input from the user.,We need to read and process the integer that the user enters.,3 "System.out.println(""Enter an integer: "");",Ask the user to enter an integer.,We prompt the user to enter an integer.,5 int num = scan.nextInt();,Get the integer that the user entered.,We read the input integer by calling the nextInt() method because this input is an integer.,4 int num = scan.nextInt();,Get the integer that the user entered.,We need to read the integer that the user enters and store it in a variable.,4 scan.close();,Close the scanner since it is not needed any more.,We close the scanner as we do not want to process any input from the user in the rest of the program.,5 if ( num > 0 ) {,Check if the number is greater than 0.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",1 if ( num > 0 ) {,Check if the number is greater than 0.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,Check if the number is greater than 0.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,Check if the number is greater than 0.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,Check if the number is greater than 0.,"If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");",Print that the number is positive if it is greater than 0.,This statement prints that the integer is positive.,4 "System.out.println(""The integer is positivie."");",Print that the number is positive if it is greater than 0.,The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,Check if the number is less than 0.,"If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",4 "System.out.println(""The integer is negative."");",Print that the integer is negative if it is less than 0.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");",Print that the integer is negative if it is less than 0.,This statement prints that the integer is negative.,5 "System.out.println(""The integer is positivie."");",Print that the integer is positive if it is greater than 0.,This statement prints that the integer is positive.,5 "System.out.println(""The integer is positivie."");",Print that the integer is positive if it is greater than 0.,The printed text is followed by the end-of-line character at the end.,1 } else {,Check if the number is not less than 0 or greater than 0.,"We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",2 "System.out.println(""The integer is zero."");",Print that the integer is zero if it is not less than 0 or greater than 0.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");",Print that the integer is zero if it is not less than 0 or greater than 0.,This statement prints that the integer is zero.,5 "int [] arr = { 1, 2, 3};",Initialize an array with some values.,We initialize the array of type int to hold the specified numbers.,4 "int [] arr = { 1, 2, 3};",Initialize an array with some values.,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,4 for ( int i = 0; i < arr.length; i++ ) {,Loop through all of the elements in the array.,We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,Loop through all of the elements in the array.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,Loop through all of the elements in the array.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,2 arr[i] += 1;,Increment the current element in the array by 1.,This statement increments the element at the index i of the array by 1.,5 for (int num = 2; num <= 10; num += 2) {,Loop through the even positive integers less than or equal to 10.,"To do this, we need to use a loop structure.",5 for (int num = 2; num <= 10; num += 2) {,Loop through the even positive integers less than or equal to 10.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,5 for (int num = 2; num <= 10; num += 2) {,Loop through the even positive integers less than or equal to 10.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",3 for (int num = 2; num <= 10; num += 2) {,Loop through the even positive integers less than or equal to 10.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,Loop through the even positive integers less than or equal to 10.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 "System.out.println(num + "" squared = "" + (num * num));",Print the current integer and its square.,The multiplication may also be performed directly in the println statement.,2 "System.out.println(num + "" squared = "" + (num * num));",Print the current integer and its square.,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",Print the current integer and its square.,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",2 "System.out.println(num + "" squared = "" + (num * num));",Print the current integer and its square.,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",4 Point1 point = new Point1();,Create a new Point1.,This statement creates a Point1 object using the new keyword and empty parentheses.,4 Point1 point = new Point1();,Create a new Point1.,The variable point holds a reference to a Point1 object.,1 point.setX(7);,Set the x coordinate of the point to 7.,This statement invokes the method setX of the point to set its x-coordinate to 7.,4 "point.translate(11, 6);",Shift the point by +11 in the x direction and +6 in the y direction.,This statement invokes the method translate of the point.,1 "point.translate(11, 6);",Shift the point by +11 in the x direction and +6 in the y direction.,The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);",Shift the point by +11 in the x direction and +6 in the y direction.,The translate method receives two parameters.,1 "point.translate(11, 6);",Shift the point by +11 in the x direction and +6 in the y direction.,The first parameter specifies how much we want to shift the x-coordinate of the point.,1 class Point1 {,Create a class called Point1.,We define the class Point1 to represent a point in the Euclidean plane.,4 private int y;,Declare the y coordinate.,"Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",4 private int y;,Declare the y coordinate.,We declare it as integer because we want to have integer coordinates for the point.,2 private int y;,Declare the y coordinate.,"Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",1 private int y;,Declare the y coordinate.,Every object of the Point1 class will have its own y-coordinate.,1 "public void translate(int dx, int dy) {",Declare the function that shifts the coordinate.,"This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",3 "public void translate(int dx, int dy) {",Declare the function that shifts the coordinate.,We define this method as public to provide access to this method from outside of the class.,1 "public void translate(int dx, int dy) {",Declare the function that shifts the coordinate.,"Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {",Declare the function that shifts the coordinate.,Note that both of the parameters are declared as integers because the point has integer coordinates.,1 x += dx;,Shift the x coordinate by dx.,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",4 public void setX(int newX) {,Declare a function that sets the x coordinate.,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,Declare a function that sets the x coordinate.,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,Declare a function that sets the x coordinate.,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,3 public void setX(int newX) {,Declare a function that sets the x coordinate.,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,Declare a function that sets the x coordinate.,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,Declare a function that sets the x coordinate.,It can be changed from outside the class only through this method.,1 public int getX() {,Declare a function that gets the current x coordinate.,We define this method as public to provide access to this method from outside of the class.,1 public int getX() {,Declare a function that gets the current x coordinate.,This method returns the x-coordinate of the point.,4 public int getX() {,Declare a function that gets the current x coordinate.,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,Declare a function that gets the current x coordinate.,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",1 public int getX() {,Declare a function that gets the current x coordinate.,It can be accessed from outside the class only through this getter method.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the x and y coordinates.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the x and y coordinates.,We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the x and y coordinates.,This statement prints the coordinates of the point to the default standard output stream.,4 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the x and y coordinates.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the x and y coordinates.,"To get the point's coordinates, we invoke the method getX and getY of the point.",1 "String fullName = ""John Smith""","Initialize the name to ""John Smith.""",We define a string variable to hold the name.,3 "String firstInitial = fullName.substring(0, 1);",Get the first initial of the name.,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",Get the first initial of the name.,"We do this by calling the substring(0,1) method.",1 "String lastInitial = fullName.substring(5, 6);",Get the last initial of the name.,We need to extract the first letter from the last name.,2 "String lastInitial = fullName.substring(5, 6);",Get the last initial of the name.,"We do this by calling the substring(5,6) method.",1 String initials = firstInitial + lastInitial;,Concatenate the first initial and last initial of the name.,This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,Print out the initials of the name.,This statement prints the initials to the default standard output stream.,5 System.out.println(initials);,Print out the initials of the name.,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Initialize the array with some values.,We define array values to hold the specified numbers.,4 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Initialize the array with some values.,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,3 int maxValue = values[0];,Initialize the maximum value to the first value in the array.,We need variable maxValue to store the maximum value of the array.,3 int maxValue = values[0];,Initialize the maximum value to the first value in the array.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,4 for (int i = 1; i < values.length; i++) {,Loop through the values in the array other than the first value.,We use a for loop to iterate over the remaining array indexes and search for the maximum value.,4 for (int i = 1; i < values.length; i++) {,Loop through the values in the array other than the first value.,We need the array indexes to start at 1 with every integer number up to but not including the array length.,3 if (values[i] > maxValue) {,Check if the current value is greater than the maximum value seen so far.,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,3 if (values[i] > maxValue) {,Check if the current value is greater than the maximum value seen so far.,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",2 maxValue = values[i];,Set the maximum value to the current value.,This statement sets the maximum value to value of the element at index i of the array.,4 "System.out.println(""Maximum value: "" + maxValue);",Print out the maximum value.,This statement prints the maximum value of the array to the default standard output stream.,5 Scanner scan = new Scanner(System.in);,Creates a scanner object to receive user inputs,"To read the input value from the user, we need to define a Scanner object.",5 Scanner scan = new Scanner(System.in);,Creates a scanner object to receive user inputs,We need to read and process the value that the user enters.,3 int num = 1234;,"This line initializes the integer ""num"" which is the number that will have it's digits printed.",We need variable num to store the integer that we want to print its digits.,4 do {,This line starts the do-while loop.,We need to process the digits of the integer from right to left and print them.,1 do {,This line starts the do-while loop.,"Therefore, we need to use a loop structure.",3 do {,This line starts the do-while loop.,"In this program, we do this by using a do loop.",4 do {,This line starts the do-while loop.,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,2 do {,"This loop will print each digit starting from the last digit, and ending with the first digit of the integer ""num""",We need to process the digits of the integer from right to left and print them.,4 do {,"This loop will print each digit starting from the last digit, and ending with the first digit of the integer ""num""","Therefore, we need to use a loop structure.",3 do {,"This loop will print each digit starting from the last digit, and ending with the first digit of the integer ""num""","In this program, we do this by using a do loop.",2 do {,"This loop will print each digit starting from the last digit, and ending with the first digit of the integer ""num""",The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,1 System.out.println(num % 10);,"This line performs a modulus calculation that gets the last digit from the integer ""num"" and prints that digit.",Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,"This line performs a modulus calculation that gets the last digit from the integer ""num"" and prints that digit.",We need to extract the last digit in the 1's position of the integer.,4 System.out.println(num % 10);,"This line performs a modulus calculation that gets the last digit from the integer ""num"" and prints that digit.","For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",2 System.out.println(num % 10);,"This line performs a modulus calculation that gets the last digit from the integer ""num"" and prints that digit.",We do this by calculating the remainder of the division of the integer by 10.,3 System.out.println(num % 10);,"This line performs a modulus calculation that gets the last digit from the integer ""num"" and prints that digit.","Then, this statement prints the last digit of the integer to the standard output stream.",4 num = num / 10;,"This divides the integer ""num"" by 10 so that the next time through the loop it gets the next digit in ""num""","Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",4 num = num / 10;,"This divides the integer ""num"" by 10 so that the next time through the loop it gets the next digit in ""num""",We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,3 num = num / 10;,"This divides the integer ""num"" by 10 so that the next time through the loop it gets the next digit in ""num""",Note that this statement performs an integer division because both operand of the / operator are integer.,3 } while (num > 0);,This is the second part of the do-while loop.,We need to check for termination conditions to avoid infinite loops.,1 } while (num > 0);,This is the second part of the do-while loop.,The loop should terminate when we run out of digits to process.,1 } while (num > 0);,This is the second part of the do-while loop.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",1 } while (num > 0);,This is the second part of the do-while loop.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",1 } while (num > 0);,This is the second part of the do-while loop.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,1 } while (num > 0);,"It makes sure this loop continues to loop through while the integer ""num"" is greater than 0.",We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,"It makes sure this loop continues to loop through while the integer ""num"" is greater than 0.",The loop should terminate when we run out of digits to process.,3 } while (num > 0);,"It makes sure this loop continues to loop through while the integer ""num"" is greater than 0.","We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",3 } while (num > 0);,"It makes sure this loop continues to loop through while the integer ""num"" is greater than 0.","If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",4 } while (num > 0);,"It makes sure this loop continues to loop through while the integer ""num"" is greater than 0.",The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,3 Scanner scan = new Scanner(System.in);,Allows the user to send input to the machine,"To read the input values from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,Allows the user to send input to the machine,We need to read and process the values that the user enters.,4 "System.out.println(""Enter the phone age in years:"");","Asks the user by printing a line that says to ""enter the phone age in years:""",We prompt the user to enter the phone age in years.,5 int phoneAge = scan.nextInt();,"This line sets the int ""phoneAge"" to the next input it receives from the user.",We read the phone age by calling the nextInt() method because this input is an integer.,3 int phoneAge = scan.nextInt();,"This line sets the int ""phoneAge"" to the next input it receives from the user.",We need to read the phone age that the user enters and store it in a variable.,4 "System.out.println(""Enter whether the phone is broken (true or false):"");","Prints the statement ""Enter whether the phone is broken (true or false):"" on the machine.",We prompt the user to enter whether the phone is broken.,5 boolean isBroken = scan.nextBoolean();,"Sets the boolean ""isBroken"" to the next input it receives from the user",We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,"Sets the boolean ""isBroken"" to the next input it receives from the user","The variable isBroken is true when the phone is broken, and false otherwise.",2 boolean isBroken = scan.nextBoolean();,"Sets the boolean ""isBroken"" to the next input it receives from the user",We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,3 scan.close();,Stops allowing the user to send input,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 boolean needPhone = isBroken || phoneAge >= 3;,Sets needPhone to true if isBroken is true or phoneAge is greater than 3.,We use the || operator (called or) to combine the two conditions.,2 boolean needPhone = isBroken || phoneAge >= 3;,Sets needPhone to true if isBroken is true or phoneAge is greater than 3.,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,Sets needPhone to true if isBroken is true or phoneAge is greater than 3.,We need two conditions to determine if it is the time for a new phone.,2 boolean needPhone = isBroken || phoneAge >= 3;,Otherwise it sets needPhone to false.,We use the || operator (called or) to combine the two conditions.,1 boolean needPhone = isBroken || phoneAge >= 3;,Otherwise it sets needPhone to false.,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,1 boolean needPhone = isBroken || phoneAge >= 3;,Otherwise it sets needPhone to false.,We need two conditions to determine if it is the time for a new phone.,1 System.out.println(needPhone);,Prints out the needPhone boolean that was set in the previous line,This statement prints true/false depending on whether it is time to buy a new phone.,5 System.out.println(needPhone);,Prints out the needPhone boolean that was set in the previous line,The printed value is followed by an end-of-line character in the end.,1 System.out.println(needPhone);,Prints out the needPhone boolean that was set in the previous line,This statement prints true/false depending on whether it is time to buy a new phone.,4 System.out.println(needPhone);,Prints out the needPhone boolean that was set in the previous line,The printed value is followed by an end-of-line character in the end.,1 "String fullName = ""John Smith""",Sets the fullName string to John Smith,We define a string variable to hold the name.,4 "String firstInitial = fullName.substring(0, 1);",Sets the firstInitial string to the first character in the fullName String.,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",Sets the firstInitial string to the first character in the fullName String.,"We do this by calling the substring(0,1) method.",2 "String lastInitial = fullName.substring(5, 6);",Sets the lastInitial string to the 6th character in the fullName string.,We need to extract the first letter from the last name.,3 "String lastInitial = fullName.substring(5, 6);",Sets the lastInitial string to the 6th character in the fullName string.,"We do this by calling the substring(5,6) method.",2 String initials = firstInitial + lastInitial;,Sets the initials string to the firstInitial and lastInitial strings combined.,This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,Prints out the string initials to the machine,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,Prints out the string initials to the machine,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};","Sets an integer array that has a set of 5 values: 5, -4, 78, 95, 12",We define array values to hold the specified numbers.,4 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};","Sets an integer array that has a set of 5 values: 5, -4, 78, 95, 12",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,3 int maxValue = values[0];,Sets the maxValue int to the first value in the array,We need variable maxValue to store the maximum value of the array.,3 int maxValue = values[0];,Sets the maxValue int to the first value in the array,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,4 for (int i = 1; i < values.length; i++) {,Starts a for loop that loops through each of the values in the values array starting from the second variable in the array.,We use a for loop to iterate over the remaining array indexes and search for the maximum value.,3 for (int i = 1; i < values.length; i++) {,Starts a for loop that loops through each of the values in the values array starting from the second variable in the array.,We need the array indexes to start at 1 with every integer number up to but not including the array length.,3 if (values[i] > maxValue) {,"If the current value in the loop is greater than maxValue, enter into the if statement.",We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,3 if (values[i] > maxValue) {,"If the current value in the loop is greater than maxValue, enter into the if statement.","If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",4 maxValue = values[i];,Sets maxValue to the current index in the values array,This statement sets the maximum value to value of the element at index i of the array.,5 "System.out.println(""Maximum value: "" + maxValue);","Prints out the statement ""Maximum value: "" and maxValue variable",This statement prints the maximum value of the array to the default standard output stream.,4 "System.out.println(""Maximum value: "" + maxValue);","Prints out the statement ""Maximum value: "" and maxValue variable",This statement prints the maximum value of the array to the default standard output stream.,4 Scanner scan = new Scanner(System.in);,Create a new scanner object with args of input.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,Create a new scanner object with args of input.,We need to read and process the integer that the user enters.,2 "System.out.println(""Enter an integer: "");",It is asking the user for an integer.,We prompt the user to enter an integer.,5 int num = scan.nextInt();,"It is assigning the value of the next entered integer to ""num"" variable.",We read the input integer by calling the nextInt() method because this input is an integer.,3 int num = scan.nextInt();,"It is assigning the value of the next entered integer to ""num"" variable.",We need to read the integer that the user enters and store it in a variable.,4 scan.close();,It is closing the the object to accepting further input.,We close the scanner as we do not want to process any input from the user in the rest of the program.,4 if ( num > 0 ) {,It is checking if the integer that was entered is greater than 0.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,It is checking if the integer that was entered is greater than 0.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,It is checking if the integer that was entered is greater than 0.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,It is checking if the integer that was entered is greater than 0.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,It is checking if the integer that was entered is greater than 0.,"If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");",It is printing out that the integer is positive.,This statement prints that the integer is positive.,5 "System.out.println(""The integer is positivie."");",It is printing out that the integer is positive.,The printed text is followed by the end-of-line character at the end.,2 } else if ( num < 0 ) {,"If it wasn't positive, it is checking if the integer was negative.","If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",5 "System.out.println(""The integer is negative."");",It is printing out that the integer was negative.,The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The integer is negative."");",It is printing out that the integer was negative.,This statement prints that the integer is negative.,5 } else {,If it is neither negative nor positive then do the following code.,"We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",4 "System.out.println(""The integer is zero."");",Print out that the integer is 0.,The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The integer is zero."");",Print out that the integer is 0.,This statement prints that the integer is zero.,5 "int [] arr = { 1, 2, 3};","Making an array that contains integer value of 1 at position 0, integer value of 2 at position 1, and integer value of 3 at position 2",We initialize the array of type int to hold the specified numbers.,3 "int [] arr = { 1, 2, 3};","Making an array that contains integer value of 1 at position 0, integer value of 2 at position 1, and integer value of 3 at position 2",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 "int [] arr = { 1, 2, 3};","Making an array that contains integer value of 1 at position 0, integer value of 2 at position 1, and integer value of 3 at position 2.",We initialize the array of type int to hold the specified numbers.,3 "int [] arr = { 1, 2, 3};","Making an array that contains integer value of 1 at position 0, integer value of 2 at position 1, and integer value of 3 at position 2.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,"Loop through the array, starting at 0, increment the position by 1 until reaching the end of the array.",We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,"Loop through the array, starting at 0, increment the position by 1 until reaching the end of the array.","To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,"Loop through the array, starting at 0, increment the position by 1 until reaching the end of the array.",We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,4 arr[i] += 1;,Add 1 to the value in the array at position i.,This statement increments the element at the index i of the array by 1.,4 Scanner scan = new Scanner(System.in);,Allows the user to type input on the machine,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,Allows the user to type input on the machine,We need to read and process the value that the user enters.,3 int seconds = scan.nextInt();,Sets the int seconds to the next input from the user,We need to read the seconds that the user enters and store it in a variable.,4 int seconds = scan.nextInt();,Sets the int seconds to the next input from the user,We read the seconds by calling the nextInt() method because this input is an integer.,3 "System.out.println(""Enter an integer for seconds: "");","Prints the line ""Enter an integer for seconds: """,We prompt the user to enter the seconds.,5 scan.close();,Disables the user's ability to type input to the machine,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 int minutes = seconds / 60;,Sets the int minutes to seconds divided by 60,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",4 int minutes = seconds / 60;,Sets the int minutes to seconds divided by 60,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,Sets remaining seconds to seconds modulus 60.,This is because there are 60 seconds in a minute.,2 int remainingSeconds = seconds % 60;,Sets remaining seconds to seconds modulus 60.,Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,Sets remaining seconds to seconds modulus 60.,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 int remainingSeconds = seconds % 60;,The modulus function gets the remainder.,This is because there are 60 seconds in a minute.,1 int remainingSeconds = seconds % 60;,The modulus function gets the remainder.,Note that the % operator returns the remainder of the division.,4 int remainingSeconds = seconds % 60;,The modulus function gets the remainder.,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "String fullName = ""John Smith""","Assigns the name-string to ""fullName""",We define a string variable to hold the name.,3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Prints out the seconds int and prints out how many minutes and remaining seconds that the int seconds is equal to.,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,5 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Prints out the seconds int and prints out how many minutes and remaining seconds that the int seconds is equal to.,The printed text is followed by the end-of-line character at the end.,2 "String firstInitial = fullName.substring(0, 1);",finds the first character in the string fullname,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",finds the first character in the string fullname,"We do this by calling the substring(0,1) method.",3 int num = 15;,Initializes the int num to 15,We define variable num to store the number that we want to find its smallest divisor.,2 int num = 15;,Initializes the int num to 15,We could initialize it to any positive integer greater than 1.,2 int num = 15;,Initializes the int num to 15,"In this program, we initialize variable num to 15.",5 int divisor = 2;,Initializes the integer divisor to 2,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,4 int divisor = 2;,Initializes the integer divisor to 2,We define variable divisor to store the smallest divisor of the number.,2 while (num % divisor != 0) {,Starts a while loop that performs as long as num modulus divisor isn't equal to 0,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",3 while (num % divisor != 0) {,Starts a while loop that performs as long as num modulus divisor isn't equal to 0,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,2 while (num % divisor != 0) {,Starts a while loop that performs as long as num modulus divisor isn't equal to 0,"Therefore, we need to use a loop structure.",2 while (num % divisor != 0) {,Starts a while loop that performs as long as num modulus divisor isn't equal to 0,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,Starts a while loop that performs as long as num modulus divisor isn't equal to 0,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,3 "String lastInitial = fullName.substring(5, 6);",finds the last character in a substring in String fullName,We need to extract the first letter from the last name.,1 "String lastInitial = fullName.substring(5, 6);",finds the last character in a substring in String fullName,"We do this by calling the substring(5,6) method.",3 divisor += 1;,Adds 1 to the int divisor,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",4 String initials = firstInitial + lastInitial;,"Sets string initials to the characters found in 6,7",This statements concatenates the extracted initials and store the result in the string initials.,3 System.out.println(initials);,outputs the string initials,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,outputs the string initials,The printed value is followed by the end-of-line character at the end.,1 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",Prints the line that states what the smallest divisor of the original num integer is using num and divisor variables.,This statement prints to the default standard output stream the smallest divisor of the number.,5 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};","assigns integer values to ""values""",We define array values to hold the specified numbers.,4 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};","assigns integer values to ""values""",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 "System.out.println(num + "" squared = "" + (num * num));",Prints a line that states what the square of num is.,The multiplication may also be performed directly in the println statement.,2 "System.out.println(num + "" squared = "" + (num * num));",Prints a line that states what the square of num is.,Note that we do not necessarily have to store the squared number in a variable.,2 "System.out.println(num + "" squared = "" + (num * num));",Prints a line that states what the square of num is.,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",2 "System.out.println(num + "" squared = "" + (num * num));",Prints a line that states what the square of num is.,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",4 "System.out.println(num + "" squared = "" + (num * num));",It will loop through this line multiple times and print out squares of every even positive integer less than or equal to 10.,The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));",It will loop through this line multiple times and print out squares of every even positive integer less than or equal to 10.,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",It will loop through this line multiple times and print out squares of every even positive integer less than or equal to 10.,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",1 "System.out.println(num + "" squared = "" + (num * num));",It will loop through this line multiple times and print out squares of every even positive integer less than or equal to 10.,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",4 for (int num = 2; num <= 10; num += 2) {,Starts a for loop that initializes an int num to 2.,"To do this, we need to use a loop structure.",4 for (int num = 2; num <= 10; num += 2) {,Starts a for loop that initializes an int num to 2.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,1 for (int num = 2; num <= 10; num += 2) {,Starts a for loop that initializes an int num to 2.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",3 for (int num = 2; num <= 10; num += 2) {,Starts a for loop that initializes an int num to 2.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,Starts a for loop that initializes an int num to 2.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 for (int num = 2; num <= 10; num += 2) {,This loop increases num by 2 at the end of every iteration and will continue to loop through as long as num is less than or equal to 10.,"To do this, we need to use a loop structure.",3 for (int num = 2; num <= 10; num += 2) {,This loop increases num by 2 at the end of every iteration and will continue to loop through as long as num is less than or equal to 10.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,4 for (int num = 2; num <= 10; num += 2) {,This loop increases num by 2 at the end of every iteration and will continue to loop through as long as num is less than or equal to 10.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",5 for (int num = 2; num <= 10; num += 2) {,This loop increases num by 2 at the end of every iteration and will continue to loop through as long as num is less than or equal to 10.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,This loop increases num by 2 at the end of every iteration and will continue to loop through as long as num is less than or equal to 10.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",4 int maxValue = values[0];,"sets integer 0 for ""maxValue""",We need variable maxValue to store the maximum value of the array.,2 int maxValue = values[0];,"sets integer 0 for ""maxValue""",We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,2 Point1 point = new Point1();,Initializes point which is a member of the point 1 class.,This statement creates a Point1 object using the new keyword and empty parentheses.,3 Point1 point = new Point1();,Initializes point which is a member of the point 1 class.,The variable point holds a reference to a Point1 object.,3 for (int i = 1; i < values.length; i++) {,"runs through the length of the ""values"" set from 1 until the length is met",We use a for loop to iterate over the remaining array indexes and search for the maximum value.,3 for (int i = 1; i < values.length; i++) {,"runs through the length of the ""values"" set from 1 until the length is met",We need the array indexes to start at 1 with every integer number up to but not including the array length.,3 point.setX(7);,Sets the x int in the point variable to 7.,This statement invokes the method setX of the point to set its x-coordinate to 7.,3 "point.translate(11, 6);",Sets the y int in the point variable to 2.,This statement invokes the method translate of the point.,1 "point.translate(11, 6);",Sets the y int in the point variable to 2.,The second parameter specifies how much we want to shift the y-coordinate of the point.,1 "point.translate(11, 6);",Sets the y int in the point variable to 2.,The translate method receives two parameters.,1 "point.translate(11, 6);",Sets the y int in the point variable to 2.,The first parameter specifies how much we want to shift the x-coordinate of the point.,1 if (values[i] > maxValue) {,"conditional set up, asking if ""values"" at i is greater than the maxValue, initially 0",We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,4 if (values[i] > maxValue) {,"conditional set up, asking if ""values"" at i is greater than the maxValue, initially 0","If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",3 maxValue = values[i];,"if previous condition met, maxValue is set to value at i",This statement sets the maximum value to value of the element at index i of the array.,4 "System.out.println(""Maximum value: "" + maxValue);",print the max value after the recursion ends,This statement prints the maximum value of the array to the default standard output stream.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",This statement invokes the method translate of the point.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The translate method receives two parameters.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The first parameter specifies how much we want to shift the x-coordinate of the point.,3 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",This statement invokes the method translate of the point.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The translate method receives two parameters.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "System.out.println(""Maximum value: "" + maxValue);",print the max value after the recursion ends,This statement prints the maximum value of the array to the default standard output stream.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",This statement invokes the method translate of the point.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The translate method receives two parameters.,2 "point.translate(11, 6);","Increases the x and y integer, which are a part of the point variable, by 11 and 6 respectively.",The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the coordinates (x and y ints) of the point variable.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the coordinates (x and y ints) of the point variable.,We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the coordinates (x and y ints) of the point variable.,This statement prints the coordinates of the point to the default standard output stream.,5 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the coordinates (x and y ints) of the point variable.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the coordinates (x and y ints) of the point variable.,"To get the point's coordinates, we invoke the method getX and getY of the point.",2 class Point1 {,Creates a class called Point1,We define the class Point1 to represent a point in the Euclidean plane.,3 private int y;,Creates an int y which is part of the Point1 class.,"Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",2 private int y;,Creates an int y which is part of the Point1 class.,We declare it as integer because we want to have integer coordinates for the point.,3 private int y;,Creates an int y which is part of the Point1 class.,"Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",1 private int y;,Creates an int y which is part of the Point1 class.,Every object of the Point1 class will have its own y-coordinate.,2 "public void translate(int dx, int dy) {",Creates a function called translate which takes 2 ints called dx and dy,"This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",4 "public void translate(int dx, int dy) {",Creates a function called translate which takes 2 ints called dx and dy,We define this method as public to provide access to this method from outside of the class.,2 "public void translate(int dx, int dy) {",Creates a function called translate which takes 2 ints called dx and dy,"Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {",Creates a function called translate which takes 2 ints called dx and dy,Note that both of the parameters are declared as integers because the point has integer coordinates.,2 x += dx;,Increases the x int in the Point1 class by dx,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",4 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,4 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class,It can be changed from outside the class only through this method.,1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class.,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class.,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class.,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,4 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class.,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class.,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,2 public void setX(int newX) {,Creates a function that sets the x int in the Point1 class.,It can be changed from outside the class only through this method.,1 public void setX(int newX) {,This function takes an int called newX.,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,This function takes an int called newX.,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,This function takes an int called newX.,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,4 public void setX(int newX) {,This function takes an int called newX.,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,This function takes an int called newX.,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,3 public void setX(int newX) {,This function takes an int called newX.,It can be changed from outside the class only through this method.,1 public int getX() {,Creates a function called getX that returns the int x in the Point1 class.,We define this method as public to provide access to this method from outside of the class.,1 public int getX() {,Creates a function called getX that returns the int x in the Point1 class.,This method returns the x-coordinate of the point.,5 public int getX() {,Creates a function called getX that returns the int x in the Point1 class.,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,Creates a function called getX that returns the int x in the Point1 class.,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",3 public int getX() {,Creates a function called getX that returns the int x in the Point1 class.,It can be accessed from outside the class only through this getter method.,1 public void setX(int newX) {,"Creates a function called setX, that sets the x int in the Point1 class.","Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,"Creates a function called setX, that sets the x int in the Point1 class.",We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,"Creates a function called setX, that sets the x int in the Point1 class.",This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,4 public void setX(int newX) {,"Creates a function called setX, that sets the x int in the Point1 class.","Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,"Creates a function called setX, that sets the x int in the Point1 class.",The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,"Creates a function called setX, that sets the x int in the Point1 class.",It can be changed from outside the class only through this method.,1 public void setX(int newX) {,This function takes an int called newX.,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,This function takes an int called newX.,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,This function takes an int called newX.,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,3 public void setX(int newX) {,This function takes an int called newX.,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,This function takes an int called newX.,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,3 public void setX(int newX) {,This function takes an int called newX.,It can be changed from outside the class only through this method.,1 Scanner scan = new Scanner(System.in);,Allows the user to send input to the machine.,"To read the input value from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Allows the user to send input to the machine.,We need to read and process the integer that the user enters.,4 "System.out.println(""Enter an integer: "");","Prints the line that says ""Enter the integer: "" on the machine.",We prompt the user to enter an integer.,4 int num = scan.nextInt();,Takes the next input from the user and initializes the int num to the input.,We read the input integer by calling the nextInt() method because this input is an integer.,4 int num = scan.nextInt();,Takes the next input from the user and initializes the int num to the input.,We need to read the integer that the user enters and store it in a variable.,4 scan.close();,Ends the ability of the user to send input to the machine.,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 if ( num > 0 ) {,if the int num is greater than 0 enter the if statement.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,if the int num is greater than 0 enter the if statement.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,if the int num is greater than 0 enter the if statement.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,if the int num is greater than 0 enter the if statement.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,if the int num is greater than 0 enter the if statement.,"If both of these tests fail, then we could conclude that the integer is zero.",2 "System.out.println(""The integer is positivie."");","Prints the line ""The integer is positive."" due to the if statement condition",This statement prints that the integer is positive.,4 "System.out.println(""The integer is positivie."");","Prints the line ""The integer is positive."" due to the if statement condition",The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,If the int num is less than 0 enter the else if statement.,"If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",2 "System.out.println(""The integer is negative."");","Prints the line ""The integer is negative."" due to the conditional else if statement.",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");","Prints the line ""The integer is negative."" due to the conditional else if statement.",This statement prints that the integer is negative.,4 "System.out.println(""The integer is zero."");","Print the line ""The integer is zero."" because the previous if and else if statements were false.",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");","Print the line ""The integer is zero."" because the previous if and else if statements were false.",This statement prints that the integer is zero.,4 } else {,"If the previous if and else if statements are false, enters the else statement.","We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",4 "int [] arr = { 1, 2, 3};","Creates an array arr that has 3 ints: 1, 2, and 3.",We initialize the array of type int to hold the specified numbers.,4 "int [] arr = { 1, 2, 3};","Creates an array arr that has 3 ints: 1, 2, and 3.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,Creates a for loop that will loop through each element of the arr array.,We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,Creates a for loop that will loop through each element of the arr array.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,Creates a for loop that will loop through each element of the arr array.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,1 arr[i] += 1;,Increases the int in the arr array at the index i by 1.,This statement increments the element at the index i of the array by 1.,5 arr[i] += 1;,This will be done for each loop and will satisfy the goal description.,This statement increments the element at the index i of the array by 1.,1 for (int num = 2; num <= 10; num += 2) {,"runs from 2 to 10, adding to to num each iteration","To do this, we need to use a loop structure.",2 for (int num = 2; num <= 10; num += 2) {,"runs from 2 to 10, adding to to num each iteration",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,3 for (int num = 2; num <= 10; num += 2) {,"runs from 2 to 10, adding to to num each iteration","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",3 for (int num = 2; num <= 10; num += 2) {,"runs from 2 to 10, adding to to num each iteration","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,"runs from 2 to 10, adding to to num each iteration","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 "System.out.println(num + "" squared = "" + (num * num));","provides output of each num added to ""squared"" added to num times num",The multiplication may also be performed directly in the println statement.,2 "System.out.println(num + "" squared = "" + (num * num));","provides output of each num added to ""squared"" added to num times num",Note that we do not necessarily have to store the squared number in a variable.,2 "System.out.println(num + "" squared = "" + (num * num));","provides output of each num added to ""squared"" added to num times num","To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",2 "System.out.println(num + "" squared = "" + (num * num));","provides output of each num added to ""squared"" added to num times num","In each iteration of the loop, this statement prints the square number to the default standard output stream.",3 Point1 point = new Point1();,"creates a new set of Point with pointer name ""point""",This statement creates a Point1 object using the new keyword and empty parentheses.,2 Point1 point = new Point1();,"creates a new set of Point with pointer name ""point""",The variable point holds a reference to a Point1 object.,4 point.setX(7);,sets the X value of point to 7,This statement invokes the method setX of the point to set its x-coordinate to 7.,4 "point.translate(11, 6);","moves the X,Y points to (11,6)",This statement invokes the method translate of the point.,2 "point.translate(11, 6);","moves the X,Y points to (11,6)",The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);","moves the X,Y points to (11,6)",The translate method receives two parameters.,2 "point.translate(11, 6);","moves the X,Y points to (11,6)",The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "point.translate(11, 6);","moves the X,Y points by adding (11,6)",This statement invokes the method translate of the point.,1 "point.translate(11, 6);","moves the X,Y points by adding (11,6)",The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);","moves the X,Y points by adding (11,6)",The translate method receives two parameters.,1 "point.translate(11, 6);","moves the X,Y points by adding (11,6)",The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","Outputs the new X,Y coordinates",Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","Outputs the new X,Y coordinates",We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","Outputs the new X,Y coordinates",This statement prints the coordinates of the point to the default standard output stream.,4 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","Outputs the new X,Y coordinates",The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","Outputs the new X,Y coordinates","To get the point's coordinates, we invoke the method getX and getY of the point.",1 class Point1 {,begins to define the class Point1,We define the class Point1 to represent a point in the Euclidean plane.,4 private int y;,"creates a private integer, y","Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",3 private int y;,"creates a private integer, y",We declare it as integer because we want to have integer coordinates for the point.,3 private int y;,"creates a private integer, y","Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",2 private int y;,"creates a private integer, y",Every object of the Point1 class will have its own y-coordinate.,3 "public void translate(int dx, int dy) {","creates ""translate"" with dependent integers dx and dy","This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",2 "public void translate(int dx, int dy) {","creates ""translate"" with dependent integers dx and dy",We define this method as public to provide access to this method from outside of the class.,1 "public void translate(int dx, int dy) {","creates ""translate"" with dependent integers dx and dy","Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {","creates ""translate"" with dependent integers dx and dy",Note that both of the parameters are declared as integers because the point has integer coordinates.,2 x += dx;,adds x dx and defines new dx as this sum,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",2 public void setX(int newX) {,assigns new setX with dependent variable newX,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,assigns new setX with dependent variable newX,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,assigns new setX with dependent variable newX,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,2 public void setX(int newX) {,assigns new setX with dependent variable newX,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,assigns new setX with dependent variable newX,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,assigns new setX with dependent variable newX,It can be changed from outside the class only through this method.,1 public void setX(int newX) {,creates a new setX with dependent variable newX,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,creates a new setX with dependent variable newX,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,creates a new setX with dependent variable newX,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,2 public void setX(int newX) {,creates a new setX with dependent variable newX,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,creates a new setX with dependent variable newX,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,creates a new setX with dependent variable newX,It can be changed from outside the class only through this method.,1 public int getX() {,"creates a public integer getX, with dependent variable x",We define this method as public to provide access to this method from outside of the class.,1 public int getX() {,"creates a public integer getX, with dependent variable x",This method returns the x-coordinate of the point.,1 public int getX() {,"creates a public integer getX, with dependent variable x","Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,"creates a public integer getX, with dependent variable x","Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",1 public int getX() {,"creates a public integer getX, with dependent variable x",It can be accessed from outside the class only through this getter method.,1 Scanner scan = new Scanner(System.in);,creates a new Scanner instance which points to the input stream passed as argument.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,creates a new Scanner instance which points to the input stream passed as argument.,We need to read and process the value that the user enters.,2 Scanner scan = new Scanner(System.in);,In this case the steam is Standard input stream,"To read the input value from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,In this case the steam is Standard input stream,We need to read and process the value that the user enters.,2 "System.out.println(""Enter an integer for seconds: "");","prints the argument (""Enter an integer for second: "") passed to the standard console and a newline",We prompt the user to enter the seconds.,4 int seconds = scan.nextInt();,"scaner object reads in a string of digits (characters) and converts them into an int type, and put them in variable entitled ""seconds""",We need to read the seconds that the user enters and store it in a variable.,4 int seconds = scan.nextInt();,"scaner object reads in a string of digits (characters) and converts them into an int type, and put them in variable entitled ""seconds""",We read the seconds by calling the nextInt() method because this input is an integer.,4 scan.close();,closes scan the input that has been opened,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 int minutes = seconds / 60;,"creates varible entitled ""minutes"" which contain calculation of variable ""second"" divided by 60","To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",4 int minutes = seconds / 60;,"creates varible entitled ""minutes"" which contain calculation of variable ""second"" divided by 60","Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",2 int remainingSeconds = seconds % 60;,"creates varible entitled ""remainingSeconds"" which contain calculation of variable ""second"" modulus by 60",This is because there are 60 seconds in a minute.,2 int remainingSeconds = seconds % 60;,"creates varible entitled ""remainingSeconds"" which contain calculation of variable ""second"" modulus by 60",Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,"creates varible entitled ""remainingSeconds"" which contain calculation of variable ""second"" modulus by 60","To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",prints in the console line the character passed inside the argument,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,2 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",prints in the console line the character passed inside the argument,The printed text is followed by the end-of-line character at the end.,1 int num = 15;,"create variable integer entitled ""num"" with value 5",We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,"create variable integer entitled ""num"" with value 5",We could initialize it to any positive integer greater than 1.,2 int num = 15;,"create variable integer entitled ""num"" with value 5","In this program, we initialize variable num to 15.",2 int divisor = 2;,"creates variable integer entitled ""division"" with initial value 2",We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,"creates variable integer entitled ""division"" with initial value 2",We define variable divisor to store the smallest divisor of the number.,2 int num = 15;,"creates variable integer entitled ""num"" with initial value 5",We define variable num to store the number that we want to find its smallest divisor.,2 int num = 15;,"creates variable integer entitled ""num"" with initial value 5",We could initialize it to any positive integer greater than 1.,2 int num = 15;,"creates variable integer entitled ""num"" with initial value 5","In this program, we initialize variable num to 15.",2 int divisor = 2;,"creates variable integer entitled ""divisor"" with initial value 2",We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,"creates variable integer entitled ""divisor"" with initial value 2",We define variable divisor to store the smallest divisor of the number.,3 while (num % divisor != 0) {,"creates looping ""while"" with condition while variable num modulus by the value of divisor is not null then execute the below code","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",3 while (num % divisor != 0) {,"creates looping ""while"" with condition while variable num modulus by the value of divisor is not null then execute the below code",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,"creates looping ""while"" with condition while variable num modulus by the value of divisor is not null then execute the below code","Therefore, we need to use a loop structure.",4 while (num % divisor != 0) {,"creates looping ""while"" with condition while variable num modulus by the value of divisor is not null then execute the below code","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,"creates looping ""while"" with condition while variable num modulus by the value of divisor is not null then execute the below code",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 divisor += 1;,add divisor variable by + 1,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",3 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",prints the character to the console with the argument inside it.,This statement prints to the default standard output stream the smallest divisor of the number.,2 Scanner scan = new Scanner(System.in);,"defines a new scanner, named ""scan"" and inputs System.in","To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,"defines a new scanner, named ""scan"" and inputs System.in",We need to read and process the integer that the user enters.,2 "System.out.println(""Enter an integer: "");",Asks user to enter an integer,We prompt the user to enter an integer.,5 int num = scan.nextInt();,"sets the user input as ""num""",We read the input integer by calling the nextInt() method because this input is an integer.,2 int num = scan.nextInt();,"sets the user input as ""num""",We need to read the integer that the user enters and store it in a variable.,4 scan.close();,terminates the input,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 "System.out.println(""The integer is positivie."");","outputs ""The integer is positive"" if num is greater than o",This statement prints that the integer is positive.,5 "System.out.println(""The integer is positivie."");","outputs ""The integer is positive"" if num is greater than o",The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,"if num is not greater than 0, condition num less than zero is next","If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",4 if ( num > 0 ) {,"begins an if-else condition, with num being larger than 0 as the first option","If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,"begins an if-else condition, with num being larger than 0 as the first option","The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",2 if ( num > 0 ) {,"begins an if-else condition, with num being larger than 0 as the first option","To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",3 if ( num > 0 ) {,"begins an if-else condition, with num being larger than 0 as the first option","Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",2 if ( num > 0 ) {,"begins an if-else condition, with num being larger than 0 as the first option","If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is negative."");","if num is less than zero, output ""The integer is negative""",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");","if num is less than zero, output ""The integer is negative""",This statement prints that the integer is negative.,4 } else {,"if the num hasn't met the first two conditions, proceed","We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",4 "System.out.println(""The integer is zero."");","output ""The integer is zero,""",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");","output ""The integer is zero,""",This statement prints that the integer is zero.,5 "int [] arr = { 1, 2, 3};",creates an int array with three integers defined,We initialize the array of type int to hold the specified numbers.,4 "int [] arr = { 1, 2, 3};",creates an int array with three integers defined,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,3 for ( int i = 0; i < arr.length; i++ ) {,"runs i from i equal to 0 the next line, adding 1 to i each time until i reaches the array length",We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,"runs i from i equal to 0 the next line, adding 1 to i each time until i reaches the array length","To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,"runs i from i equal to 0 the next line, adding 1 to i each time until i reaches the array length",We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,5 arr[i] += 1;,adds 1 to array position each iteration,This statement increments the element at the index i of the array by 1.,4 int num = 1234;,the number that will be printed,We need variable num to store the integer that we want to print its digits.,3 do {,loop start,We need to process the digits of the integer from right to left and print them.,1 do {,loop start,"Therefore, we need to use a loop structure.",3 do {,loop start,"In this program, we do this by using a do loop.",2 do {,loop start,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,2 System.out.println(num % 10);,number output,Each printed digit is followed by the line separator (e.g. '\n') at the end.,2 System.out.println(num % 10);,number output,We need to extract the last digit in the 1's position of the integer.,1 System.out.println(num % 10);,number output,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",1 System.out.println(num % 10);,number output,We do this by calculating the remainder of the division of the integer by 10.,1 System.out.println(num % 10);,number output,"Then, this statement prints the last digit of the integer to the standard output stream.",3 num = num / 10;,go to the next number,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",3 num = num / 10;,go to the next number,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,1 num = num / 10;,go to the next number,Note that this statement performs an integer division because both operand of the / operator are integer.,1 } while (num > 0);,loop condition,We need to check for termination conditions to avoid infinite loops.,3 } while (num > 0);,loop condition,The loop should terminate when we run out of digits to process.,2 } while (num > 0);,loop condition,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",2 } while (num > 0);,loop condition,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",2 } while (num > 0);,loop condition,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,1 int num = 1234;,"sets ""num"" to the integer 1234",We need variable num to store the integer that we want to print its digits.,2 do {,initiates a do/while task,We need to process the digits of the integer from right to left and print them.,1 do {,initiates a do/while task,"Therefore, we need to use a loop structure.",2 do {,initiates a do/while task,"In this program, we do this by using a do loop.",3 do {,initiates a do/while task,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,2 System.out.println(num % 10);,print the remainder of num divided by 10,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,print the remainder of num divided by 10,We need to extract the last digit in the 1's position of the integer.,3 System.out.println(num % 10);,print the remainder of num divided by 10,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",1 System.out.println(num % 10);,print the remainder of num divided by 10,We do this by calculating the remainder of the division of the integer by 10.,4 System.out.println(num % 10);,print the remainder of num divided by 10,"Then, this statement prints the last digit of the integer to the standard output stream.",3 System.out.println(num % 10);,print the remainder of num divided by 10,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,print the remainder of num divided by 10,We need to extract the last digit in the 1's position of the integer.,3 System.out.println(num % 10);,print the remainder of num divided by 10,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",2 System.out.println(num % 10);,print the remainder of num divided by 10,We do this by calculating the remainder of the division of the integer by 10.,4 System.out.println(num % 10);,print the remainder of num divided by 10,"Then, this statement prints the last digit of the integer to the standard output stream.",3 num = num / 10;,reset num to num divided by 10,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",3 num = num / 10;,reset num to num divided by 10,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,3 num = num / 10;,reset num to num divided by 10,Note that this statement performs an integer division because both operand of the / operator are integer.,2 } while (num > 0);,continue do-task while num is greater than zero,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,continue do-task while num is greater than zero,The loop should terminate when we run out of digits to process.,3 } while (num > 0);,continue do-task while num is greater than zero,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",4 } while (num > 0);,continue do-task while num is greater than zero,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",4 } while (num > 0);,continue do-task while num is greater than zero,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,3 Scanner scan = new Scanner(System.in);,"define a new Scanner named ""scan"" using sytem input","To read the input values from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,"define a new Scanner named ""scan"" using sytem input",We need to read and process the values that the user enters.,2 "System.out.println(""Enter the phone age in years:"");","outputs ""Enter the phone age in years"" for user to respond to",We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,defines a new int as the input from the user,We read the phone age by calling the nextInt() method because this input is an integer.,3 int phoneAge = scan.nextInt();,defines a new int as the input from the user,We need to read the phone age that the user enters and store it in a variable.,3 "System.out.println(""Enter whether the phone is broken (true or false):"");",Asks user a true or false question,We prompt the user to enter whether the phone is broken.,3 boolean isBroken = scan.nextBoolean();,creates a boolean variable defined by the user input,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,creates a boolean variable defined by the user input,"The variable isBroken is true when the phone is broken, and false otherwise.",2 boolean isBroken = scan.nextBoolean();,creates a boolean variable defined by the user input,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 scan.close();,ends input capability,We close the scanner as we do not want to process any input from the user in the rest of the program.,4 Scanner scan = new Scanner(System.in);,Data entry,"To read the input values from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Data entry,We need to read and process the values that the user enters.,3 "System.out.println(""Enter the phone age in years:"");","On-screen display ""Enter the phone age in years:""",We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,Telphone age entry,We read the phone age by calling the nextInt() method because this input is an integer.,2 int phoneAge = scan.nextInt();,Telphone age entry,We need to read the phone age that the user enters and store it in a variable.,2 "System.out.println(""Enter whether the phone is broken (true or false):"");","Shows the phrase: ""Enter whether the phone is broken (true or false):""",We prompt the user to enter whether the phone is broken.,4 boolean isBroken = scan.nextBoolean();,Whether it is broken or not,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,Whether it is broken or not,"The variable isBroken is true when the phone is broken, and false otherwise.",2 boolean isBroken = scan.nextBoolean();,Whether it is broken or not,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 scan.close();,Closes entries,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 boolean needPhone = isBroken || phoneAge >= 3;,determines a boolean (T/F) based on what the user inputted or if the phoneAge value is greater than or equal to 3,We use the || operator (called or) to combine the two conditions.,3 boolean needPhone = isBroken || phoneAge >= 3;,determines a boolean (T/F) based on what the user inputted or if the phoneAge value is greater than or equal to 3,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,4 boolean needPhone = isBroken || phoneAge >= 3;,determines a boolean (T/F) based on what the user inputted or if the phoneAge value is greater than or equal to 3,We need two conditions to determine if it is the time for a new phone.,3 boolean needPhone = isBroken || phoneAge >= 3;,Conditions if a new phone is needed,We use the || operator (called or) to combine the two conditions.,2 boolean needPhone = isBroken || phoneAge >= 3;,Conditions if a new phone is needed,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,2 boolean needPhone = isBroken || phoneAge >= 3;,Conditions if a new phone is needed,We need two conditions to determine if it is the time for a new phone.,3 System.out.println(needPhone);,Shows whether it is necessary or not,This statement prints true/false depending on whether it is time to buy a new phone.,3 System.out.println(needPhone);,Shows whether it is necessary or not,The printed value is followed by an end-of-line character in the end.,1 System.out.println(needPhone);,"outputs the boolean result of ""needPhone""",This statement prints true/false depending on whether it is time to buy a new phone.,4 System.out.println(needPhone);,"outputs the boolean result of ""needPhone""",The printed value is followed by an end-of-line character in the end.,1 "String fullName = ""John Smith""",Stores the name,We define a string variable to hold the name.,4 "String firstInitial = fullName.substring(0, 1);",Retrieves the initial of the first name,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",Retrieves the initial of the first name,"We do this by calling the substring(0,1) method.",2 "String lastInitial = fullName.substring(5, 6);",Retrieves the initial of the least name,We need to extract the first letter from the last name.,4 "String lastInitial = fullName.substring(5, 6);",Retrieves the initial of the least name,"We do this by calling the substring(5,6) method.",1 String initials = firstInitial + lastInitial;,Join the two initials,This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,Shows initials,This statement prints the initials to the default standard output stream.,3 System.out.println(initials);,Shows initials,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Values to be analyzed,We define array values to hold the specified numbers.,3 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Values to be analyzed,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,1 int maxValue = values[0];,Variable that will store the maximum value,We need variable maxValue to store the maximum value of the array.,4 int maxValue = values[0];,Variable that will store the maximum value,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,2 for (int i = 1; i < values.length; i++) {,Loop start,We use a for loop to iterate over the remaining array indexes and search for the maximum value.,2 for (int i = 1; i < values.length; i++) {,Loop start,We need the array indexes to start at 1 with every integer number up to but not including the array length.,1 if (values[i] > maxValue) {,First condition,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,2 if (values[i] > maxValue) {,First condition,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",1 "System.out.println(""Maximum value: "" + maxValue);",Prints the result,This statement prints the maximum value of the array to the default standard output stream.,3 maxValue = values[i];,Recovers the maximum value,This statement sets the maximum value to value of the element at index i of the array.,2 for (int num = 2; num <= 10; num += 2) {,Loop structure,"To do this, we need to use a loop structure.",4 for (int num = 2; num <= 10; num += 2) {,Loop structure,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,2 for (int num = 2; num <= 10; num += 2) {,Loop structure,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,Loop structure,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,Loop structure,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",2 "System.out.println(num + "" squared = "" + (num * num));",Prints the result,The multiplication may also be performed directly in the println statement.,2 "System.out.println(num + "" squared = "" + (num * num));",Prints the result,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",Prints the result,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",1 "System.out.println(num + "" squared = "" + (num * num));",Prints the result,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",2 Point1 point = new Point1();,Stores the point,This statement creates a Point1 object using the new keyword and empty parentheses.,2 Point1 point = new Point1();,Stores the point,The variable point holds a reference to a Point1 object.,1 point.setX(7);,Set the X axis,This statement invokes the method setX of the point to set its x-coordinate to 7.,3 "point.translate(11, 6);",Joins the x and y axis values,This statement invokes the method translate of the point.,1 "point.translate(11, 6);",Joins the x and y axis values,The second parameter specifies how much we want to shift the y-coordinate of the point.,1 "point.translate(11, 6);",Joins the x and y axis values,The translate method receives two parameters.,1 "point.translate(11, 6);",Joins the x and y axis values,The first parameter specifies how much we want to shift the x-coordinate of the point.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the axes,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the axes,We could use the returned value of them directly in the println statement.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the axes,This statement prints the coordinates of the point to the default standard output stream.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the axes,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Prints the axes,"To get the point's coordinates, we invoke the method getX and getY of the point.",1 class Point1 {,Creates the Point1 class,We define the class Point1 to represent a point in the Euclidean plane.,3 private int y;,Variable Y,"Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",2 private int y;,Variable Y,We declare it as integer because we want to have integer coordinates for the point.,1 private int y;,Variable Y,"Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",1 private int y;,Variable Y,Every object of the Point1 class will have its own y-coordinate.,2 "public void translate(int dx, int dy) {",Axles,"This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",1 "public void translate(int dx, int dy) {",Axles,We define this method as public to provide access to this method from outside of the class.,1 "public void translate(int dx, int dy) {",Axles,"Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {",Axles,Note that both of the parameters are declared as integers because the point has integer coordinates.,1 x += dx;,Changes the X axis,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",2 public void setX(int newX) {,New X axis,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,New X axis,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,New X axis,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,2 public void setX(int newX) {,New X axis,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,New X axis,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,New X axis,It can be changed from outside the class only through this method.,1 public int getX() {,Recovers the X axis,We define this method as public to provide access to this method from outside of the class.,1 public int getX() {,Recovers the X axis,This method returns the x-coordinate of the point.,3 public int getX() {,Recovers the X axis,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,Recovers the X axis,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",1 public int getX() {,Recovers the X axis,It can be accessed from outside the class only through this getter method.,1 Scanner scan = new Scanner(System.in);,Set input,"To read the input value from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Set input,We need to read and process the value that the user enters.,2 "System.out.println(""Enter an integer for seconds: "");","Display the message ""Enter an integer for seconds:""",We prompt the user to enter the seconds.,4 int seconds = scan.nextInt();,Creates the variable seconds,We need to read the seconds that the user enters and store it in a variable.,3 int seconds = scan.nextInt();,Creates the variable seconds,We read the seconds by calling the nextInt() method because this input is an integer.,2 for (int num = 2; num <= 10; num += 2) {,"This for loop will first assign the num variable to 2, execute what is in the body and then increment num by 2 (which guarantees that num is positive) each round until num reaches the value 10.","To do this, we need to use a loop structure.",3 for (int num = 2; num <= 10; num += 2) {,"This for loop will first assign the num variable to 2, execute what is in the body and then increment num by 2 (which guarantees that num is positive) each round until num reaches the value 10.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,3 for (int num = 2; num <= 10; num += 2) {,"This for loop will first assign the num variable to 2, execute what is in the body and then increment num by 2 (which guarantees that num is positive) each round until num reaches the value 10.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",4 for (int num = 2; num <= 10; num += 2) {,"This for loop will first assign the num variable to 2, execute what is in the body and then increment num by 2 (which guarantees that num is positive) each round until num reaches the value 10.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,"This for loop will first assign the num variable to 2, execute what is in the body and then increment num by 2 (which guarantees that num is positive) each round until num reaches the value 10.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",4 for (int num = 2; num <= 10; num += 2) {,"Since num must be <= 10 to execute what code is in the body of the function, the code in the body will execute for num = 10 as well.","To do this, we need to use a loop structure.",1 for (int num = 2; num <= 10; num += 2) {,"Since num must be <= 10 to execute what code is in the body of the function, the code in the body will execute for num = 10 as well.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,2 for (int num = 2; num <= 10; num += 2) {,"Since num must be <= 10 to execute what code is in the body of the function, the code in the body will execute for num = 10 as well.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,"Since num must be <= 10 to execute what code is in the body of the function, the code in the body will execute for num = 10 as well.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,"Since num must be <= 10 to execute what code is in the body of the function, the code in the body will execute for num = 10 as well.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 int minutes = seconds / 60;,Create the variable minutes,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",2 int minutes = seconds / 60;,Create the variable minutes,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,Stores the missing seconds,This is because there are 60 seconds in a minute.,1 int remainingSeconds = seconds % 60;,Stores the missing seconds,Note that the % operator returns the remainder of the division.,1 int remainingSeconds = seconds % 60;,Stores the missing seconds,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",1 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Output,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,2 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Output,The printed text is followed by the end-of-line character at the end.,1 int num = 15;,Creates the variable num,We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,Creates the variable num,We could initialize it to any positive integer greater than 1.,1 int num = 15;,Creates the variable num,"In this program, we initialize variable num to 15.",2 "System.out.println(num + "" squared = "" + (num * num));",This code will print what the current num is and its squared value.,The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));",This code will print what the current num is and its squared value.,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",This code will print what the current num is and its squared value.,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",2 "System.out.println(num + "" squared = "" + (num * num));",This code will print what the current num is and its squared value.,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",3 "System.out.println(num + "" squared = "" + (num * num));","For instance, if num is 4 it will print ""4 squared = 16"".",The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));","For instance, if num is 4 it will print ""4 squared = 16"".",Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));","For instance, if num is 4 it will print ""4 squared = 16"".","To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",1 "System.out.println(num + "" squared = "" + (num * num));","For instance, if num is 4 it will print ""4 squared = 16"".","In each iteration of the loop, this statement prints the square number to the default standard output stream.",2 int divisor = 2;,Creates the variable divisor,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,Creates the variable divisor,We define variable divisor to store the smallest divisor of the number.,3 while (num % divisor != 0) {,Loop start,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,Loop start,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,Loop start,"Therefore, we need to use a loop structure.",2 while (num % divisor != 0) {,Loop start,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",1 while (num % divisor != 0) {,Loop start,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,1 divisor += 1;,Find the new divisor,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",2 scan.close();,Closes the entrance,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",Output,This statement prints to the default standard output stream the smallest divisor of the number.,2 Point1 point = new Point1();,This line instantiates a brand new Point1 object.,This statement creates a Point1 object using the new keyword and empty parentheses.,3 Point1 point = new Point1();,This line instantiates a brand new Point1 object.,The variable point holds a reference to a Point1 object.,2 Scanner scan = new Scanner(System.in);,Set input start,"To read the input value from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Set input start,We need to read and process the integer that the user enters.,2 "System.out.println(""Enter an integer: "");","Prints the phrase ""Enter an integer:""",We prompt the user to enter an integer.,4 int num = scan.nextInt();,"Creates the variable ""num""",We read the input integer by calling the nextInt() method because this input is an integer.,1 int num = scan.nextInt();,"Creates the variable ""num""",We need to read the integer that the user enters and store it in a variable.,2 point.setX(7);,This sets the x variable defined by the Point1 object to 7.,This statement invokes the method setX of the point to set its x-coordinate to 7.,4 scan.close();,Close input,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 if ( num > 0 ) {,"Finds ""num"" greater than zero","If the integer is neither positive nor negative, then we could conclude that the integer is zero.",1 if ( num > 0 ) {,"Finds ""num"" greater than zero","The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,"Finds ""num"" greater than zero","To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",1 if ( num > 0 ) {,"Finds ""num"" greater than zero","Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,"Finds ""num"" greater than zero","If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");",Prints if the number is positive,This statement prints that the integer is positive.,4 "System.out.println(""The integer is positivie."");",Prints if the number is positive,The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,"Finds ""num"" less than zero","If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",2 "point.translate(11, 6);",This increments the x variable from the Point1 object by 11 and also increments the y variable by 6.,This statement invokes the method translate of the point.,2 "point.translate(11, 6);",This increments the x variable from the Point1 object by 11 and also increments the y variable by 6.,The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);",This increments the x variable from the Point1 object by 11 and also increments the y variable by 6.,The translate method receives two parameters.,1 "point.translate(11, 6);",This increments the x variable from the Point1 object by 11 and also increments the y variable by 6.,The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "System.out.println(""The integer is negative."");",Output if the number is negative,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");",Output if the number is negative,This statement prints that the integer is negative.,5 Scanner scan = new Scanner(System.in);,"introduce a new input scanner named ""scan""","To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,"introduce a new input scanner named ""scan""",We need to read and process the value that the user enters.,2 } else {,If it is not negative or positive,"We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",3 "System.out.println(""The integer is zero."");",Prints that the number is equal to 0,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");",Prints that the number is equal to 0,This statement prints that the integer is zero.,5 "System.out.println(""Enter an integer for seconds: "");",Ask the user to input an integer for seconds,We prompt the user to enter the seconds.,5 "int [] arr = { 1, 2, 3};","Creates the variable ""arr""",We initialize the array of type int to hold the specified numbers.,1 "int [] arr = { 1, 2, 3};","Creates the variable ""arr""",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,This statement prints the coordinates of the point to the default standard output stream.,4 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,"To get the point's coordinates, we invoke the method getX and getY of the point.",4 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,This statement prints the coordinates of the point to the default standard output stream.,4 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints out the current point1 object's x and y variables by using .getX and .getY functions that return the data stored in those variables.,"To get the point's coordinates, we invoke the method getX and getY of the point.",4 int seconds = scan.nextInt();,"set user input to int named ""seconds""",We need to read the seconds that the user enters and store it in a variable.,4 int seconds = scan.nextInt();,"set user input to int named ""seconds""",We read the seconds by calling the nextInt() method because this input is an integer.,2 arr[i] += 1;,"New value of ""arr""",This statement increments the element at the index i of the array by 1.,1 for ( int i = 0; i < arr.length; i++ ) {,Loop start,We want to iterate over the array and increment each element in the array by 1.,2 for ( int i = 0; i < arr.length; i++ ) {,Loop start,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,Loop start,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,1 scan.close();,stop the scan input function,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 int minutes = seconds / 60;,"define integer ""minutes"" as ""seconds"" divided by 60","To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",4 int minutes = seconds / 60;,"define integer ""minutes"" as ""seconds"" divided by 60","Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 for (int num = 2; num <= 10; num += 2) {,"Num will be set to two and incremented by 2 (guaranteeing even values) after the for loop executes the body in the code each time, until num reaches 10.","To do this, we need to use a loop structure.",2 for (int num = 2; num <= 10; num += 2) {,"Num will be set to two and incremented by 2 (guaranteeing even values) after the for loop executes the body in the code each time, until num reaches 10.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,4 for (int num = 2; num <= 10; num += 2) {,"Num will be set to two and incremented by 2 (guaranteeing even values) after the for loop executes the body in the code each time, until num reaches 10.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",4 for (int num = 2; num <= 10; num += 2) {,"Num will be set to two and incremented by 2 (guaranteeing even values) after the for loop executes the body in the code each time, until num reaches 10.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,"Num will be set to two and incremented by 2 (guaranteeing even values) after the for loop executes the body in the code each time, until num reaches 10.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 int remainingSeconds = seconds % 60;,"define the remainder of seconds/60 as ""remainingSeconds"" integer",This is because there are 60 seconds in a minute.,1 int remainingSeconds = seconds % 60;,"define the remainder of seconds/60 as ""remainingSeconds"" integer",Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,"define the remainder of seconds/60 as ""remainingSeconds"" integer","To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""",The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""",Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""","To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",3 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""","In each iteration of the loop, this statement prints the square number to the default standard output stream.",4 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""",The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""",Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""","To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",3 "System.out.println(num + "" squared = "" + (num * num));","This line prints the current value of num and its squared value, for instance if num = 4, it will print ""4.squared = 16""","In each iteration of the loop, this statement prints the square number to the default standard output stream.",3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",output the integers to the user,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",output the integers to the user,The printed text is followed by the end-of-line character at the end.,1 Point1 point = new Point1();,This line instantiates a new Point1 object named point.,This statement creates a Point1 object using the new keyword and empty parentheses.,4 Point1 point = new Point1();,This line instantiates a new Point1 object named point.,The variable point holds a reference to a Point1 object.,3 int num = 15;,"define integer ""num"" as 15",We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,"define integer ""num"" as 15",We could initialize it to any positive integer greater than 1.,1 int num = 15;,"define integer ""num"" as 15","In this program, we initialize variable num to 15.",5 point.setX(7);,This line sets the variable x within the Point1 object to 7.,This statement invokes the method setX of the point to set its x-coordinate to 7.,4 int divisor = 2;,"define integer ""divisor"" as 2",We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,"define integer ""divisor"" as 2",We define variable divisor to store the smallest divisor of the number.,3 "point.translate(11, 6);",This line increments the variable x within the Point1 object by 11 and the y variable by 6.,This statement invokes the method translate of the point.,3 "point.translate(11, 6);",This line increments the variable x within the Point1 object by 11 and the y variable by 6.,The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);",This line increments the variable x within the Point1 object by 11 and the y variable by 6.,The translate method receives two parameters.,1 "point.translate(11, 6);",This line increments the variable x within the Point1 object by 11 and the y variable by 6.,The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints the current value of the x and y variables within the Point1 object.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints the current value of the x and y variables within the Point1 object.,We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints the current value of the x and y variables within the Point1 object.,This statement prints the coordinates of the point to the default standard output stream.,4 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints the current value of the x and y variables within the Point1 object.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This prints the current value of the x and y variables within the Point1 object.,"To get the point's coordinates, we invoke the method getX and getY of the point.",2 class Point1 {,This defines the class Point1.,We define the class Point1 to represent a point in the Euclidean plane.,4 class Point1 {,Everything that follows after the opening bracket is part of the Point1 class (until closing bracket).,We define the class Point1 to represent a point in the Euclidean plane.,2 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,"Therefore, we need to use a loop structure.",4 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,3 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",3 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,"Therefore, we need to use a loop structure.",4 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,run a while-loop as long as the remainder of num/divisor is not equal to 0,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,3 private int y;,This line creates a private integer y variable to later be defined.,"Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",2 private int y;,This line creates a private integer y variable to later be defined.,We declare it as integer because we want to have integer coordinates for the point.,3 private int y;,This line creates a private integer y variable to later be defined.,"Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",2 private int y;,This line creates a private integer y variable to later be defined.,Every object of the Point1 class will have its own y-coordinate.,1 "public void translate(int dx, int dy) {",This defines the function translate and its parameters x and y.,"This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",4 "public void translate(int dx, int dy) {",This defines the function translate and its parameters x and y.,We define this method as public to provide access to this method from outside of the class.,2 "public void translate(int dx, int dy) {",This defines the function translate and its parameters x and y.,"Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {",This defines the function translate and its parameters x and y.,Note that both of the parameters are declared as integers because the point has integer coordinates.,2 divisor += 1;,"keep the adding 1 to newly defined ""divisor"" for each iteration","When the divisor is not a factor of the number, we increment the variable divisor by 1.",4 x += dx;,"this line adds the arguments the user gives to the function, to x.","To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",4 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,We define this method as public to provide access to this method from outside of the class.,2 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,3 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,3 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,It can be changed from outside the class only through this method.,1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,3 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,3 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,It can be changed from outside the class only through this method.,1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,"Also, we define its return type as void, as it does not return any value.",2 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,We define this method as public to provide access to this method from outside of the class.,2 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,3 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,3 public void setX(int newX) {,This defines the function setX and describes what parameters it should take (an int).,It can be changed from outside the class only through this method.,1 public int getX() {,defines fucntion getX,We define this method as public to provide access to this method from outside of the class.,2 public int getX() {,defines fucntion getX,This method returns the x-coordinate of the point.,2 public int getX() {,defines fucntion getX,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,defines fucntion getX,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",2 public int getX() {,defines fucntion getX,It can be accessed from outside the class only through this getter method.,1 public int getX() {,defines fucntion getX,We define this method as public to provide access to this method from outside of the class.,2 public int getX() {,defines fucntion getX,This method returns the x-coordinate of the point.,2 public int getX() {,defines fucntion getX,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,defines fucntion getX,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",2 public int getX() {,defines fucntion getX,It can be accessed from outside the class only through this getter method.,1 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);","output the result of ""divisor""'s last value to the user",This statement prints to the default standard output stream the smallest divisor of the number.,3 "String fullName = ""John Smith""","This stores the String ""John Smith"" into a string variable named fullName.",We define a string variable to hold the name.,4 "String fullName = ""John Smith""",fullName can later be used to get the data (initials) from it.,We define a string variable to hold the name.,1 "String firstInitial = fullName.substring(0, 1);",This uses the fullName variable to get the first character from it and store it in a variable string called firstInitial.,We need to extract the first letter from the first name.,3 "String firstInitial = fullName.substring(0, 1);",This uses the fullName variable to get the first character from it and store it in a variable string called firstInitial.,"We do this by calling the substring(0,1) method.",2 "String lastInitial = fullName.substring(5, 6);",This uses the fullName variable to get the 6th character from it and store it in a variable string called lastInitial.,We need to extract the first letter from the last name.,3 "String lastInitial = fullName.substring(5, 6);",This uses the fullName variable to get the 6th character from it and store it in a variable string called lastInitial.,"We do this by calling the substring(5,6) method.",2 String initials = firstInitial + lastInitial;,This creates a new string called initials by combining the firstInitial and lastInitial string.,This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,This prints out the initials.,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,This prints out the initials.,The printed value is followed by the end-of-line character at the end.,1 System.out.println(initials);,This prints out the initials.,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,This prints out the initials.,The printed value is followed by the end-of-line character at the end.,1 Scanner scan = new Scanner(System.in);,This creates a new scanner object called scan.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,This creates a new scanner object called scan.,We need to read and process the integer that the user enters.,2 Scanner scan = new Scanner(System.in);,scan can later be used to help retrieve user input.,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,scan can later be used to help retrieve user input.,We need to read and process the integer that the user enters.,4 "System.out.println(""Enter an integer: "");","This prints out ""Enter an integer: "" which tells the user what to do.",We prompt the user to enter an integer.,4 int num = scan.nextInt();,This saves what ever the user entered into an int variable called num/.,We read the input integer by calling the nextInt() method because this input is an integer.,3 int num = scan.nextInt();,This saves what ever the user entered into an int variable called num/.,We need to read the integer that the user enters and store it in a variable.,4 scan.close();,This closes / end the scanner since it will no longer be used.,We close the scanner as we do not want to process any input from the user in the rest of the program.,5 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",3 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"If both of these tests fail, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"If both of these tests fail, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,It can be used to check if the value is positive.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,It can be used to check if the value is positive.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,It can be used to check if the value is positive.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",3 if ( num > 0 ) {,It can be used to check if the value is positive.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,It can be used to check if the value is positive.,"If both of these tests fail, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,This checks whether the value given by the user was greater than 0.,"If both of these tests fail, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,It can be used to check if the value is positive.,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,It can be used to check if the value is positive.,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,It can be used to check if the value is positive.,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,It can be used to check if the value is positive.,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,It can be used to check if the value is positive.,"If both of these tests fail, then we could conclude that the integer is zero.",2 "System.out.println(""The integer is positivie."");","This prints out ""The integer is positive"" so that the user knows that their value is positive.",This statement prints that the integer is positive.,4 "System.out.println(""The integer is positivie."");","This prints out ""The integer is positive"" so that the user knows that their value is positive.",The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,This checks if num is negative only when num fails to be positive.,"If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",4 "System.out.println(""The integer is negative."");","This prints that ""the integer is negative"" so that the user knows that the value is negative.",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");","This prints that ""the integer is negative"" so that the user knows that the value is negative.",This statement prints that the integer is negative.,4 } else {,This allows for the codes within the else brackets to execute only if the num is not neg or positive.,"We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",4 "System.out.println(""The integer is zero."");",This prints that the integer was zero so that the user knows that their value was 0.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");",This prints that the integer was zero so that the user knows that their value was 0.,This statement prints that the integer is zero.,4 "int [] arr = { 1, 2, 3};","This stores the array [1,2,3] in a variable called arr so that the elements in arr can later be incremented.",We initialize the array of type int to hold the specified numbers.,4 "int [] arr = { 1, 2, 3};","This stores the array [1,2,3] in a variable called arr so that the elements in arr can later be incremented.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,This loop will iterate through all elements in the array so that all values can be incremented.,We want to iterate over the array and increment each element in the array by 1.,4 for ( int i = 0; i < arr.length; i++ ) {,This loop will iterate through all elements in the array so that all values can be incremented.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,This loop will iterate through all elements in the array so that all values can be incremented.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,3 arr[i] += 1;,This grabs the value stored in index i of the array and increments it by 1 and adds it back to the array.,This statement increments the element at the index i of the array by 1.,4 Scanner scan = new Scanner(System.in);,This initiates a new scanner object with a variable name of scan.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,This initiates a new scanner object with a variable name of scan.,We need to read and process the value that the user enters.,1 Scanner scan = new Scanner(System.in);,scan can be used to get input from the user.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,scan can be used to get input from the user.,We need to read and process the value that the user enters.,4 Scanner scan = new Scanner(System.in);,This initiates a new scanner object with a variable name of scan.,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,This initiates a new scanner object with a variable name of scan.,We need to read and process the value that the user enters.,1 Scanner scan = new Scanner(System.in);,scan can be used to get input from the user.,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,scan can be used to get input from the user.,We need to read and process the value that the user enters.,4 "System.out.println(""Enter an integer for seconds: "");","This prints out ""Enter an integer for seconds:"" so that the user knows what to enter.",We prompt the user to enter the seconds.,4 int seconds = scan.nextInt();,This gets user input and saves it in an int variable called seconds.,We need to read the seconds that the user enters and store it in a variable.,4 int seconds = scan.nextInt();,This gets user input and saves it in an int variable called seconds.,We read the seconds by calling the nextInt() method because this input is an integer.,3 scan.close();,This closes scan since it will not be used anymore.,We close the scanner as we do not want to process any input from the user in the rest of the program.,5 int minutes = seconds / 60;,This divides the integer value that the user entered by 60 and saves it in a variable called minutes.,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",3 int minutes = seconds / 60;,This divides the integer value that the user entered by 60 and saves it in a variable called minutes.,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,This takes the modulus of user input and 60 and saves it into an int variable named remaining Seconds.,This is because there are 60 seconds in a minute.,1 int remainingSeconds = seconds % 60;,This takes the modulus of user input and 60 and saves it into an int variable named remaining Seconds.,Note that the % operator returns the remainder of the division.,1 int remainingSeconds = seconds % 60;,This takes the modulus of user input and 60 and saves it into an int variable named remaining Seconds.,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",2 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",This prints out the previously define minutes and remainingSeconds data.,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",This prints out the previously define minutes and remainingSeconds data.,The printed text is followed by the end-of-line character at the end.,1 int num = 15;,This saves the integer 15 to a variable called num.,We define variable num to store the number that we want to find its smallest divisor.,1 int num = 15;,This saves the integer 15 to a variable called num.,We could initialize it to any positive integer greater than 1.,1 int num = 15;,This saves the integer 15 to a variable called num.,"In this program, we initialize variable num to 15.",2 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We define variable divisor to store the smallest divisor of the number.,2 while (num % divisor != 0) {,"While divisor is not a divisor of num, the body in the while function will execute.","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,"While divisor is not a divisor of num, the body in the while function will execute.",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,"While divisor is not a divisor of num, the body in the while function will execute.","Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,"While divisor is not a divisor of num, the body in the while function will execute.","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,"While divisor is not a divisor of num, the body in the while function will execute.",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,3 divisor += 1;,"This increments divisor by one, so that in the next round, the while loop will check whether the data in divisor is a divisor of num.","When the divisor is not a factor of the number, we increment the variable divisor by 1.",4 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We define variable divisor to store the smallest divisor of the number.,3 int divisor = 2;,This is the smallest possible divisor (greater than 1) of any number.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,This is the smallest possible divisor (greater than 1) of any number.,We define variable divisor to store the smallest divisor of the number.,2 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We define variable divisor to store the smallest divisor of the number.,4 int divisor = 2;,This is the smallest possible divisor (greater than 1) of any number.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,This is the smallest possible divisor (greater than 1) of any number.,We define variable divisor to store the smallest divisor of the number.,2 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,This saves the integer 2 into a variable called divisor.,We define variable divisor to store the smallest divisor of the number.,4 int divisor = 2;,This is the smallest possible divisor (greater than 1) of any number.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,This is the smallest possible divisor (greater than 1) of any number.,We define variable divisor to store the smallest divisor of the number.,2 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",This prints out what the smallest divisor of the number is.,This statement prints to the default standard output stream the smallest divisor of the number.,4 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 int num = 1234;,"We need to initialize an integer variable which will hold an arbitrary integer value, so that we can perform the necessary operation of extracting its digits from right to left.",We need variable num to store the integer that we want to print its digits.,3 do {,"It's the beginning of a do while loop, we need the program to loop through the length of the number, so as to extract the digits.",We need to process the digits of the integer from right to left and print them.,3 do {,"It's the beginning of a do while loop, we need the program to loop through the length of the number, so as to extract the digits.","Therefore, we need to use a loop structure.",3 do {,"It's the beginning of a do while loop, we need the program to loop through the length of the number, so as to extract the digits.","In this program, we do this by using a do loop.",2 do {,"It's the beginning of a do while loop, we need the program to loop through the length of the number, so as to extract the digits.",The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,3 System.out.println(num % 10);,"This line of code , prints the last digit, that is the right most digit of the number.",Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,"This line of code , prints the last digit, that is the right most digit of the number.",We need to extract the last digit in the 1's position of the integer.,3 System.out.println(num % 10);,"This line of code , prints the last digit, that is the right most digit of the number.","For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",2 System.out.println(num % 10);,"This line of code , prints the last digit, that is the right most digit of the number.",We do this by calculating the remainder of the division of the integer by 10.,1 System.out.println(num % 10);,"This line of code , prints the last digit, that is the right most digit of the number.","Then, this statement prints the last digit of the integer to the standard output stream.",4 System.out.println(num % 10);,"This works by taking its reminder when divided by 10, using the %(modulo) operator.",Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,"This works by taking its reminder when divided by 10, using the %(modulo) operator.",We need to extract the last digit in the 1's position of the integer.,2 System.out.println(num % 10);,"This works by taking its reminder when divided by 10, using the %(modulo) operator.","For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",1 System.out.println(num % 10);,"This works by taking its reminder when divided by 10, using the %(modulo) operator.",We do this by calculating the remainder of the division of the integer by 10.,4 System.out.println(num % 10);,"This works by taking its reminder when divided by 10, using the %(modulo) operator.","Then, this statement prints the last digit of the integer to the standard output stream.",1 int num = 1234;,"This saves the integer, whose digits will be printed from left to right, in a variable called num.",We need variable num to store the integer that we want to print its digits.,2 num = num / 10;,"After extracting the right most digit, we need to get rid of it from the number.","Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",4 num = num / 10;,"After extracting the right most digit, we need to get rid of it from the number.",We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,2 num = num / 10;,"After extracting the right most digit, we need to get rid of it from the number.",Note that this statement performs an integer division because both operand of the / operator are integer.,1 num = num / 10;,"To do that, we simply divide the integer number by 10, and the end result is a the same number without the right most digit.","Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",2 num = num / 10;,"To do that, we simply divide the integer number by 10, and the end result is a the same number without the right most digit.",We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,2 num = num / 10;,"To do that, we simply divide the integer number by 10, and the end result is a the same number without the right most digit.",Note that this statement performs an integer division because both operand of the / operator are integer.,1 num = num / 10;,After that we replace the previous num value with this value (the one with the right most digit removed).,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",3 num = num / 10;,After that we replace the previous num value with this value (the one with the right most digit removed).,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,2 num = num / 10;,After that we replace the previous num value with this value (the one with the right most digit removed).,Note that this statement performs an integer division because both operand of the / operator are integer.,1 do {,The code in the body of the do will first execute and continue to execute while the while function is true.,We need to process the digits of the integer from right to left and print them.,1 do {,The code in the body of the do will first execute and continue to execute while the while function is true.,"Therefore, we need to use a loop structure.",1 do {,The code in the body of the do will first execute and continue to execute while the while function is true.,"In this program, we do this by using a do loop.",1 do {,The code in the body of the do will first execute and continue to execute while the while function is true.,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,1 } while (num > 0);,This is the continuation test.,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,This is the continuation test.,The loop should terminate when we run out of digits to process.,1 } while (num > 0);,This is the continuation test.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",1 } while (num > 0);,This is the continuation test.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",1 } while (num > 0);,This is the continuation test.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,1 } while (num > 0);,This is what drives the loop.,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,This is what drives the loop.,The loop should terminate when we run out of digits to process.,2 } while (num > 0);,This is what drives the loop.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",1 } while (num > 0);,This is what drives the loop.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",1 } while (num > 0);,This is what drives the loop.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,1 } while (num > 0);,"As long as the number doesn't reduce to 0 , we keep running this loop.",We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,"As long as the number doesn't reduce to 0 , we keep running this loop.",The loop should terminate when we run out of digits to process.,2 } while (num > 0);,"As long as the number doesn't reduce to 0 , we keep running this loop.","We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",3 } while (num > 0);,"As long as the number doesn't reduce to 0 , we keep running this loop.","If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",2 } while (num > 0);,"As long as the number doesn't reduce to 0 , we keep running this loop.",The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,4 } while (num > 0);,The loop is terminated once all the digits have been printed and the number reduces to 0.,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,The loop is terminated once all the digits have been printed and the number reduces to 0.,The loop should terminate when we run out of digits to process.,3 } while (num > 0);,The loop is terminated once all the digits have been printed and the number reduces to 0.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",2 } while (num > 0);,The loop is terminated once all the digits have been printed and the number reduces to 0.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",2 } while (num > 0);,The loop is terminated once all the digits have been printed and the number reduces to 0.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,3 System.out.println(num % 10);,This line prints out what right most integer of the current num by using the modulus function.,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,This line prints out what right most integer of the current num by using the modulus function.,We need to extract the last digit in the 1's position of the integer.,3 System.out.println(num % 10);,This line prints out what right most integer of the current num by using the modulus function.,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",2 System.out.println(num % 10);,This line prints out what right most integer of the current num by using the modulus function.,We do this by calculating the remainder of the division of the integer by 10.,3 System.out.println(num % 10);,This line prints out what right most integer of the current num by using the modulus function.,"Then, this statement prints the last digit of the integer to the standard output stream.",3 int num = 1234;,"This saves the integer, whose digits will be printed from right to left, in a variable called num.",We need variable num to store the integer that we want to print its digits.,3 num = num / 10;,This will update the new num by removing the right most digit of the current num.,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",3 num = num / 10;,This will update the new num by removing the right most digit of the current num.,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,2 num = num / 10;,This will update the new num by removing the right most digit of the current num.,Note that this statement performs an integer division because both operand of the / operator are integer.,1 } while (num > 0);,This allows the code in the do body to execute while num is greater than 0.,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,This allows the code in the do body to execute while num is greater than 0.,The loop should terminate when we run out of digits to process.,2 } while (num > 0);,This allows the code in the do body to execute while num is greater than 0.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",2 } while (num > 0);,This allows the code in the do body to execute while num is greater than 0.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",2 } while (num > 0);,This allows the code in the do body to execute while num is greater than 0.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,2 Scanner scan = new Scanner(System.in);,"We created a scanner object, which is the object required to take input from user.","To read the input values from the user, we need to define a Scanner object.",5 Scanner scan = new Scanner(System.in);,"We created a scanner object, which is the object required to take input from user.",We need to read and process the values that the user enters.,3 Scanner scan = new Scanner(System.in);,This creates a Scanner object called scan so that it could be used to retrieve data from user input.,"To read the input values from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,This creates a Scanner object called scan so that it could be used to retrieve data from user input.,We need to read and process the values that the user enters.,3 "System.out.println(""Enter the phone age in years:"");","This prints out: ""Enter the phone age in years:"" so that the user will know what to enter.",We prompt the user to enter the phone age in years.,4 "System.out.println(""Enter the phone age in years:"");","We print output on the screen with the message ""Enter the phone age in years"", asking the user to input phone age.",We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,This saves the user input in a variable called phone age so that the program can test whether its time to get a new phone.,We read the phone age by calling the nextInt() method because this input is an integer.,2 int phoneAge = scan.nextInt();,This saves the user input in a variable called phone age so that the program can test whether its time to get a new phone.,We need to read the phone age that the user enters and store it in a variable.,3 "System.out.println(""Enter whether the phone is broken (true or false):"");","This prints out ""Enter whether the phone is broken (true or false):"" so that the user knows what to enter.",We prompt the user to enter whether the phone is broken.,4 int phoneAge = scan.nextInt();,"We initialize an integer variable named phoneAge, and scan the user input and store it in it.",We read the phone age by calling the nextInt() method because this input is an integer.,3 int phoneAge = scan.nextInt();,"We initialize an integer variable named phoneAge, and scan the user input and store it in it.",We need to read the phone age that the user enters and store it in a variable.,4 boolean isBroken = scan.nextBoolean();,This scans the new input that the user just submitted and saves it into a boolean variable called isBroken.,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,This scans the new input that the user just submitted and saves it into a boolean variable called isBroken.,"The variable isBroken is true when the phone is broken, and false otherwise.",1 boolean isBroken = scan.nextBoolean();,This scans the new input that the user just submitted and saves it into a boolean variable called isBroken.,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,3 scan.close();,This closes the scan object since it will no longer be used.,We close the scanner as we do not want to process any input from the user in the rest of the program.,5 "System.out.println(""Enter whether the phone is broken (true or false):"");","We print message to the user, asking to enter whether the phone has been broken or not.",We prompt the user to enter whether the phone is broken.,5 "System.out.println(""Enter whether the phone is broken (true or false):"");",The input should be either True or False.,We prompt the user to enter whether the phone is broken.,1 boolean isBroken = scan.nextBoolean();,we declare a Boolean variable isBroken and scan the user input and store it in this variable.,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,we declare a Boolean variable isBroken and scan the user input and store it in this variable.,"The variable isBroken is true when the phone is broken, and false otherwise.",1 boolean isBroken = scan.nextBoolean();,we declare a Boolean variable isBroken and scan the user input and store it in this variable.,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 boolean needPhone = isBroken || phoneAge >= 3;,"This will save true to the variable needPhone if either the phone is 3 or more years old or if the user entered true if the phone is broken, else it will save needPhone as false.",We use the || operator (called or) to combine the two conditions.,2 boolean needPhone = isBroken || phoneAge >= 3;,"This will save true to the variable needPhone if either the phone is 3 or more years old or if the user entered true if the phone is broken, else it will save needPhone as false.",The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,"This will save true to the variable needPhone if either the phone is 3 or more years old or if the user entered true if the phone is broken, else it will save needPhone as false.",We need two conditions to determine if it is the time for a new phone.,3 scan.close();,"After we are done taking input, we close the scanner object using this line.",We close the scanner as we do not want to process any input from the user in the rest of the program.,4 System.out.println(needPhone);,This prints out true or false based on the information given to the program by the user.,This statement prints true/false depending on whether it is time to buy a new phone.,5 System.out.println(needPhone);,This prints out true or false based on the information given to the program by the user.,The printed value is followed by an end-of-line character in the end.,1 boolean needPhone = isBroken || phoneAge >= 3;,if the phone is broken or age is more than 3 then bolean true will be stored in the variable.,We use the || operator (called or) to combine the two conditions.,2 boolean needPhone = isBroken || phoneAge >= 3;,if the phone is broken or age is more than 3 then bolean true will be stored in the variable.,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,if the phone is broken or age is more than 3 then bolean true will be stored in the variable.,We need two conditions to determine if it is the time for a new phone.,3 Scanner scan = new Scanner(System.in);,We create a scanner object named scan.,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,We create a scanner object named scan.,We need to read and process the integer that the user enters.,2 Scanner scan = new Scanner(System.in);,It will be used to take input from user.,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,It will be used to take input from user.,We need to read and process the integer that the user enters.,3 "System.out.println(""Enter an integer: "");","We print to the user interface, ""Enter an integer"" asking the user to input an integer.",We prompt the user to enter an integer.,4 int num = scan.nextInt();,"the scanner object scans the number as a string, reading one character at a time and converting it to an integer, using the method nextInt() and storing the result in the integer variable num.",We read the input integer by calling the nextInt() method because this input is an integer.,3 int num = scan.nextInt();,"the scanner object scans the number as a string, reading one character at a time and converting it to an integer, using the method nextInt() and storing the result in the integer variable num.",We need to read the integer that the user enters and store it in a variable.,3 scan.close();,We then close the scanner object.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 scan.close();,No more input needed.,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 if ( num > 0 ) {,"Beginning of an if statement , if num is greater than 0 then the code enclosed by if will be terminated.","If the integer is neither positive nor negative, then we could conclude that the integer is zero.",1 if ( num > 0 ) {,"Beginning of an if statement , if num is greater than 0 then the code enclosed by if will be terminated.","The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",2 if ( num > 0 ) {,"Beginning of an if statement , if num is greater than 0 then the code enclosed by if will be terminated.","To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",1 if ( num > 0 ) {,"Beginning of an if statement , if num is greater than 0 then the code enclosed by if will be terminated.","Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",2 if ( num > 0 ) {,"Beginning of an if statement , if num is greater than 0 then the code enclosed by if will be terminated.","If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");","Once meeting the if criteria, this line of code prints to the user ""The integer is positive"" .",This statement prints that the integer is positive.,4 "System.out.println(""The integer is positivie."");","Once meeting the if criteria, this line of code prints to the user ""The integer is positive"" .",The printed text is followed by the end-of-line character at the end.,2 } else if ( num < 0 ) {,"If the if criteria is not met, then the else if criteria is checked, that is , if the num is less than 0.","If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",3 "System.out.println(""The integer is negative."");","if the else if criteria is met, the this line prints to the user, ""The integer is negative"".",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");","if the else if criteria is met, the this line prints to the user, ""The integer is negative"".",This statement prints that the integer is negative.,4 "System.out.println(""The integer is negative."");","if the else if criteria is met, the this line prints to the user, ""The integer is negative"".",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");","if the else if criteria is met, the this line prints to the user, ""The integer is negative"".",This statement prints that the integer is negative.,4 } else {,"if none of the criteria meets then the code enclosed by else is executed, that is , it prints to the user ""The integer is zero"" .","We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",2 } else {,if none of the criteria meets then the code enclosed by else is executed.,"We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",3 "System.out.println(""The integer is zero."");","If none of the criteria meets, then this line prints to the user ""The integer is zero"".",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");","If none of the criteria meets, then this line prints to the user ""The integer is zero"".",This statement prints that the integer is zero.,3 "int [] arr = { 1, 2, 3};","we declare an integer array, with its elements initialized.",We initialize the array of type int to hold the specified numbers.,4 "int [] arr = { 1, 2, 3};","we declare an integer array, with its elements initialized.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,3 "int [] arr = { 1, 2, 3};","Namely 1,2 and 3.",We initialize the array of type int to hold the specified numbers.,1 "int [] arr = { 1, 2, 3};","Namely 1,2 and 3.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,1 for ( int i = 0; i < arr.length; i++ ) {,It's a for loop.,We want to iterate over the array and increment each element in the array by 1.,2 for ( int i = 0; i < arr.length; i++ ) {,It's a for loop.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,It's a for loop.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,1 for ( int i = 0; i < arr.length; i++ ) {,"The loop starts with the iteration variable value as 0 and runs as long as the its value is less than the length of the array length, incrementing it's value by 1 each time because of i++ .",We want to iterate over the array and increment each element in the array by 1.,4 for ( int i = 0; i < arr.length; i++ ) {,"The loop starts with the iteration variable value as 0 and runs as long as the its value is less than the length of the array length, incrementing it's value by 1 each time because of i++ .","To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,"The loop starts with the iteration variable value as 0 and runs as long as the its value is less than the length of the array length, incrementing it's value by 1 each time because of i++ .",We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,3 arr[i] += 1;,"in each iteration, the value of the array element whose index value is equal to the value of the iteration variable , is incremented by 1.",This statement increments the element at the index i of the array by 1.,3 Scanner scan = new Scanner(System.in);,"We create a scanner object to scan inputs from user, that is , the input.","To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,"We create a scanner object to scan inputs from user, that is , the input.",We need to read and process the value that the user enters.,3 "System.out.println(""Enter an integer for seconds: "");","We print a message to the user on screen, ""Enter an integer for seconds"", asking them to input the value.",We prompt the user to enter the seconds.,4 int seconds = scan.nextInt();,we store the scanned input into an integer variable named seconds.,We need to read the seconds that the user enters and store it in a variable.,4 int seconds = scan.nextInt();,we store the scanned input into an integer variable named seconds.,We read the seconds by calling the nextInt() method because this input is an integer.,4 scan.close();,We then close the scan object.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 int minutes = seconds / 60;,We divide the seconds by 60 and store the results in another integer variable named minutes.,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",3 int minutes = seconds / 60;,We divide the seconds by 60 and store the results in another integer variable named minutes.,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,We then take the remainder of the division of seconds by 60 and store it into the variable named remainingSeconds .,This is because there are 60 seconds in a minute.,2 int remainingSeconds = seconds % 60;,We then take the remainder of the division of seconds by 60 and store it into the variable named remainingSeconds .,Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,We then take the remainder of the division of seconds by 60 and store it into the variable named remainingSeconds .,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");","we then print to the user on screen: seconds(the value stored by this variable) + ""second is"" + minutes(the value stored by this variable) + ""minutes and"" + remainingSeconds(the value stored by this variable) + "" seconds.""",This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,4 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");","we then print to the user on screen: seconds(the value stored by this variable) + ""second is"" + minutes(the value stored by this variable) + ""minutes and"" + remainingSeconds(the value stored by this variable) + "" seconds.""",The printed text is followed by the end-of-line character at the end.,1 int num = 15;,We initialize an integer variable named num with the value 15.,We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,We initialize an integer variable named num with the value 15.,We could initialize it to any positive integer greater than 1.,3 int num = 15;,We initialize an integer variable named num with the value 15.,"In this program, we initialize variable num to 15.",4 int divisor = 2;,we initialize another variable named divisor with the value 2.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,we initialize another variable named divisor with the value 2.,We define variable divisor to store the smallest divisor of the number.,3 while (num % divisor != 0) {,"We begin a while loop, with the condition that the remainder when num is divided by divisor is not equal to 0.","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",3 while (num % divisor != 0) {,"We begin a while loop, with the condition that the remainder when num is divided by divisor is not equal to 0.",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,1 while (num % divisor != 0) {,"We begin a while loop, with the condition that the remainder when num is divided by divisor is not equal to 0.","Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,"We begin a while loop, with the condition that the remainder when num is divided by divisor is not equal to 0.","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,"We begin a while loop, with the condition that the remainder when num is divided by divisor is not equal to 0.",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 while (num % divisor != 0) {,"If this holds true, then the loop will be executed.","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,"If this holds true, then the loop will be executed.",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,2 while (num % divisor != 0) {,"If this holds true, then the loop will be executed.","Therefore, we need to use a loop structure.",2 while (num % divisor != 0) {,"If this holds true, then the loop will be executed.","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",1 while (num % divisor != 0) {,"If this holds true, then the loop will be executed.",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 divisor += 1;,If the while condition is true then the value of 1 is assigned to the divisor.,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",1 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);","after exiting the loop, we print to the user on screen ""The smallest divisor of "" + num( the value of this variable) + ""is"" divisor (the value of this variable).",This statement prints to the default standard output stream the smallest divisor of the number.,3 for (int num = 2; num <= 10; num += 2) {,It's a for loop.,"To do this, we need to use a loop structure.",3 for (int num = 2; num <= 10; num += 2) {,It's a for loop.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,1 for (int num = 2; num <= 10; num += 2) {,It's a for loop.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",1 for (int num = 2; num <= 10; num += 2) {,It's a for loop.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,It's a for loop.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",1 for (int num = 2; num <= 10; num += 2) {,The iteration variable num is initialized with 2.,"To do this, we need to use a loop structure.",1 for (int num = 2; num <= 10; num += 2) {,The iteration variable num is initialized with 2.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,1 for (int num = 2; num <= 10; num += 2) {,The iteration variable num is initialized with 2.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,The iteration variable num is initialized with 2.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,The iteration variable num is initialized with 2.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 for (int num = 2; num <= 10; num += 2) {,"The control condition is that if num is less than or equal to 10 , then the statement enclosed by the loop will be executed.","To do this, we need to use a loop structure.",3 for (int num = 2; num <= 10; num += 2) {,"The control condition is that if num is less than or equal to 10 , then the statement enclosed by the loop will be executed.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,4 for (int num = 2; num <= 10; num += 2) {,"The control condition is that if num is less than or equal to 10 , then the statement enclosed by the loop will be executed.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,"The control condition is that if num is less than or equal to 10 , then the statement enclosed by the loop will be executed.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,"The control condition is that if num is less than or equal to 10 , then the statement enclosed by the loop will be executed.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",2 for (int num = 2; num <= 10; num += 2) {,"After each iteration, the iteration variable's value is incremented by 2.","To do this, we need to use a loop structure.",1 for (int num = 2; num <= 10; num += 2) {,"After each iteration, the iteration variable's value is incremented by 2.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,1 for (int num = 2; num <= 10; num += 2) {,"After each iteration, the iteration variable's value is incremented by 2.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",4 for (int num = 2; num <= 10; num += 2) {,"After each iteration, the iteration variable's value is incremented by 2.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,"After each iteration, the iteration variable's value is incremented by 2.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",1 "System.out.println(num + "" squared = "" + (num * num));","if the control condition is true, then the system prints to the user on screen num(value of this variable) +"" squared= "" + (num *num) (product of num with num).",The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));","if the control condition is true, then the system prints to the user on screen num(value of this variable) +"" squared= "" + (num *num) (product of num with num).",Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));","if the control condition is true, then the system prints to the user on screen num(value of this variable) +"" squared= "" + (num *num) (product of num with num).","To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",2 "System.out.println(num + "" squared = "" + (num * num));","if the control condition is true, then the system prints to the user on screen num(value of this variable) +"" squared= "" + (num *num) (product of num with num).","In each iteration of the loop, this statement prints the square number to the default standard output stream.",2 Point1 point = new Point1();,"an object of the class Point1 is created, named point.",This statement creates a Point1 object using the new keyword and empty parentheses.,3 Point1 point = new Point1();,"an object of the class Point1 is created, named point.",The variable point holds a reference to a Point1 object.,1 point.setX(7);,the point object's setter function/method is called. It assigns value to the point object's x coordinate.,This statement invokes the method setX of the point to set its x-coordinate to 7.,3 "point.translate(11, 6);",The translate method of the object is called.,This statement invokes the method translate of the point.,5 "point.translate(11, 6);",The translate method of the object is called.,The second parameter specifies how much we want to shift the y-coordinate of the point.,1 "point.translate(11, 6);",The translate method of the object is called.,The translate method receives two parameters.,2 "point.translate(11, 6);",The translate method of the object is called.,The first parameter specifies how much we want to shift the x-coordinate of the point.,1 "point.translate(11, 6);","It increments the value of the x coordinate by 11 , while it increases the value of the y coordinate by 6.",This statement invokes the method translate of the point.,1 "point.translate(11, 6);","It increments the value of the x coordinate by 11 , while it increases the value of the y coordinate by 6.",The second parameter specifies how much we want to shift the y-coordinate of the point.,1 "point.translate(11, 6);","It increments the value of the x coordinate by 11 , while it increases the value of the y coordinate by 6.",The translate method receives two parameters.,1 "point.translate(11, 6);","It increments the value of the x coordinate by 11 , while it increases the value of the y coordinate by 6.",The first parameter specifies how much we want to shift the x-coordinate of the point.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This line then prints to the screen the point's coordinates.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This line then prints to the screen the point's coordinates.,We could use the returned value of them directly in the println statement.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This line then prints to the screen the point's coordinates.,This statement prints the coordinates of the point to the default standard output stream.,3 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This line then prints to the screen the point's coordinates.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This line then prints to the screen the point's coordinates.,"To get the point's coordinates, we invoke the method getX and getY of the point.",1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This is done by calling the respective getter functions which are used to get the x and y coordinate values of the points.,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This is done by calling the respective getter functions which are used to get the x and y coordinate values of the points.,We could use the returned value of them directly in the println statement.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This is done by calling the respective getter functions which are used to get the x and y coordinate values of the points.,This statement prints the coordinates of the point to the default standard output stream.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This is done by calling the respective getter functions which are used to get the x and y coordinate values of the points.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",This is done by calling the respective getter functions which are used to get the x and y coordinate values of the points.,"To get the point's coordinates, we invoke the method getX and getY of the point.",3 class Point1 {,"It is the beginning line of the creation of a class , here, Point1",We define the class Point1 to represent a point in the Euclidean plane.,3 "public void translate(int dx, int dy) {","this is beginning line of the translate method of the class Point1, it has two integers as its arguments, dx and dy","This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",3 "public void translate(int dx, int dy) {","this is beginning line of the translate method of the class Point1, it has two integers as its arguments, dx and dy",We define this method as public to provide access to this method from outside of the class.,1 "public void translate(int dx, int dy) {","this is beginning line of the translate method of the class Point1, it has two integers as its arguments, dx and dy","Also, we define its return type as void, as it does not return any value.",2 "public void translate(int dx, int dy) {","this is beginning line of the translate method of the class Point1, it has two integers as its arguments, dx and dy",Note that both of the parameters are declared as integers because the point has integer coordinates.,2 private int y;,"it's a private variable of type int, accessible only by the getter and setter functions of the class Point1.","Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",2 private int y;,"it's a private variable of type int, accessible only by the getter and setter functions of the class Point1.",We declare it as integer because we want to have integer coordinates for the point.,2 private int y;,"it's a private variable of type int, accessible only by the getter and setter functions of the class Point1.","Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",1 private int y;,"it's a private variable of type int, accessible only by the getter and setter functions of the class Point1.",Every object of the Point1 class will have its own y-coordinate.,2 x += dx;,the x coordinate value of the class is incremented by the value of the variable dx.,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",3 public void setX(int newX) {,"this is the setter method of the class, it sets the value of the x coordinate.","Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,"this is the setter method of the class, it sets the value of the x coordinate.",We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,"this is the setter method of the class, it sets the value of the x coordinate.",This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,2 public void setX(int newX) {,"this is the setter method of the class, it sets the value of the x coordinate.","Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,"this is the setter method of the class, it sets the value of the x coordinate.",The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,"this is the setter method of the class, it sets the value of the x coordinate.",It can be changed from outside the class only through this method.,1 public int getX() {,"this is the getter method of the class, it gets the value of the coordinate of the class object.",We define this method as public to provide access to this method from outside of the class.,1 public int getX() {,"this is the getter method of the class, it gets the value of the coordinate of the class object.",This method returns the x-coordinate of the point.,3 public int getX() {,"this is the getter method of the class, it gets the value of the coordinate of the class object.","Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,"this is the getter method of the class, it gets the value of the coordinate of the class object.","Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",2 public int getX() {,"this is the getter method of the class, it gets the value of the coordinate of the class object.",It can be accessed from outside the class only through this getter method.,2 "String fullName = ""John Smith""","The string ""John Smith"" is stored in the string variable fullname.",We define a string variable to hold the name.,3 "String firstInitial = fullName.substring(0, 1);","It stores ""J"" in a string variable firstInitial, that is it stores the first initial.",We need to extract the first letter from the first name.,2 "String firstInitial = fullName.substring(0, 1);","It stores ""J"" in a string variable firstInitial, that is it stores the first initial.","We do this by calling the substring(0,1) method.",1 "String lastInitial = fullName.substring(5, 6);","this code stores the last initial of the name here ,""S"" , in the variable named lastInitial",We need to extract the first letter from the last name.,3 "String lastInitial = fullName.substring(5, 6);","this code stores the last initial of the name here ,""S"" , in the variable named lastInitial","We do this by calling the substring(5,6) method.",2 String initials = firstInitial + lastInitial;,the firstInitial and the lastInitial are then stored together in the variable named initals.,This statements concatenates the extracted initials and store the result in the string initials.,3 System.out.println(initials);,the value of the string variable initials is then printed out to the user on system screen.,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,the value of the string variable initials is then printed out to the user on system screen.,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};","an integer array is initialized with the values given. 5, -4, 78, 95, 12.",We define array values to hold the specified numbers.,4 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};","an integer array is initialized with the values given. 5, -4, 78, 95, 12.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 int maxValue = values[0];,the first value of the array is stored in the integer variable maxValue .,We need variable maxValue to store the maximum value of the array.,3 int maxValue = values[0];,the first value of the array is stored in the integer variable maxValue .,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,3 for (int i = 1; i < values.length; i++) {,"a for loop is created , with the iterator variable's value being 1, and the control condition being that the iterator variable's value should be less than the array length.",We use a for loop to iterate over the remaining array indexes and search for the maximum value.,2 for (int i = 1; i < values.length; i++) {,"a for loop is created , with the iterator variable's value being 1, and the control condition being that the iterator variable's value should be less than the array length.",We need the array indexes to start at 1 with every integer number up to but not including the array length.,2 if (values[i] > maxValue) {,"this is an if statement , with the condition that if the array element , whose index value is equal to that of the iterator variable is greater than the value of the variable maxValue, then the code enclosed by it will be executed.",We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,2 if (values[i] > maxValue) {,"this is an if statement , with the condition that if the array element , whose index value is equal to that of the iterator variable is greater than the value of the variable maxValue, then the code enclosed by it will be executed.","If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",2 maxValue = values[i];,the value of the element in the array at the index of the iterator variable is assigned to maxValue .,This statement sets the maximum value to value of the element at index i of the array.,3 "System.out.println(""Maximum value: "" + maxValue);","system prints ""Maximum value: "" + maxValue",This statement prints the maximum value of the array to the default standard output stream.,3 "String fullName = ""John Smith""",This is the data used for the problem.,We define a string variable to hold the name.,1 "String fullName = ""John Smith""","Since we want to print the initials of John Smith, we define this name as a string.",We define a string variable to hold the name.,3 "String firstInitial = fullName.substring(0, 1);",We obtain the first character of the first word by taking a single character substring from the beginning of the string.,We need to extract the first letter from the first name.,3 "String firstInitial = fullName.substring(0, 1);",We obtain the first character of the first word by taking a single character substring from the beginning of the string.,"We do this by calling the substring(0,1) method.",5 "String lastInitial = fullName.substring(5, 6);","Now, we take the first character of the second part of the name by taking a second substring.",We need to extract the first letter from the last name.,3 "String lastInitial = fullName.substring(5, 6);","Now, we take the first character of the second part of the name by taking a second substring.","We do this by calling the substring(5,6) method.",2 String initials = firstInitial + lastInitial;,We add these two characters together to get the initials.,This statements concatenates the extracted initials and store the result in the string initials.,5 System.out.println(initials);,Now we print the initials we obtained,This statement prints the initials to the default standard output stream.,3 System.out.println(initials);,Now we print the initials we obtained,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Initialize our array of values,We define array values to hold the specified numbers.,3 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Initialize our array of values,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 int maxValue = values[0];,Initialize a max value which we compare the rest of the array to by taking the first value in the array.,We need variable maxValue to store the maximum value of the array.,3 int maxValue = values[0];,Initialize a max value which we compare the rest of the array to by taking the first value in the array.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,2 for (int i = 1; i < values.length; i++) {,Step through the array element by element starting at the second element,We use a for loop to iterate over the remaining array indexes and search for the maximum value.,2 for (int i = 1; i < values.length; i++) {,Step through the array element by element starting at the second element,We need the array indexes to start at 1 with every integer number up to but not including the array length.,2 if (values[i] > maxValue) {,Compare the element at the current index of the array to our stored max element,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,4 if (values[i] > maxValue) {,Compare the element at the current index of the array to our stored max element,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",1 maxValue = values[i];,Store the new max element,This statement sets the maximum value to value of the element at index i of the array.,2 "System.out.println(""Maximum value: "" + maxValue);",Print the maximum value we found,This statement prints the maximum value of the array to the default standard output stream.,3 "System.out.println(""Maximum value: "" + maxValue);",Print the maximum value we found,This statement prints the maximum value of the array to the default standard output stream.,3 Scanner scan = new Scanner(System.in);,Set up the scanner to read in values,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,Set up the scanner to read in values,We need to read and process the integer that the user enters.,3 "System.out.println(""Enter an integer: "");",Instruct the user to enter an integer,We prompt the user to enter an integer.,5 int num = scan.nextInt();,Read in the user submitted value as an integer,We read the input integer by calling the nextInt() method because this input is an integer.,3 int num = scan.nextInt();,Read in the user submitted value as an integer,We need to read the integer that the user enters and store it in a variable.,4 scan.close();,Stop reading in input values,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 if ( num > 0 ) {,Check if the number is positive,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",2 if ( num > 0 ) {,Check if the number is positive,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,Check if the number is positive,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",2 if ( num > 0 ) {,Check if the number is positive,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,Check if the number is positive,"If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");",Notify the user that the number is positive,This statement prints that the integer is positive.,4 "System.out.println(""The integer is positivie."");",Notify the user that the number is positive,The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,Check if the number is negative,"If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",2 "System.out.println(""The integer is negative."");",Notify the user that the number found is negative,The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The integer is negative."");",Notify the user that the number found is negative,This statement prints that the integer is negative.,4 } else {,Default to the value zero as the number was neither positive nor negative,"We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",2 "System.out.println(""The integer is zero."");",Notify the user that the entered number is zero,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");",Notify the user that the entered number is zero,This statement prints that the integer is zero.,5 "int [] arr = { 1, 2, 3};",Set up the array of integers to increment.,We initialize the array of type int to hold the specified numbers.,2 "int [] arr = { 1, 2, 3};",Set up the array of integers to increment.,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,Step through each element of the array starting from the first and going to the last,We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,Step through each element of the array starting from the first and going to the last,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,Step through each element of the array starting from the first and going to the last,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,4 arr[i] += 1;,Add one to the element at the current index of the array to increment the value.,This statement increments the element at the index i of the array by 1.,4 Scanner scan = new Scanner(System.in);,Set up a scanner to read in user submitted inputs,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,Set up a scanner to read in user submitted inputs,We need to read and process the value that the user enters.,3 "System.out.println(""Enter an integer for seconds: "");",Notify the user to input a time value in seconds,We prompt the user to enter the seconds.,3 int seconds = scan.nextInt();,Read in the user input as an integer,We need to read the seconds that the user enters and store it in a variable.,3 int seconds = scan.nextInt();,Read in the user input as an integer,We read the seconds by calling the nextInt() method because this input is an integer.,2 scan.close();,Close the scanner to stop reading in inputs,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 int minutes = seconds / 60;,Generate a total number of minutes by doing integer division,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",2 int minutes = seconds / 60;,Generate a total number of minutes by doing integer division,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,Find the remainder after finding the number of minutes by using the modulo operator,This is because there are 60 seconds in a minute.,1 int remainingSeconds = seconds % 60;,Find the remainder after finding the number of minutes by using the modulo operator,Note that the % operator returns the remainder of the division.,3 int remainingSeconds = seconds % 60;,Find the remainder after finding the number of minutes by using the modulo operator,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Print out the input time value as a number of minutes and seconds,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Print out the input time value as a number of minutes and seconds,The printed text is followed by the end-of-line character at the end.,1 int num = 15;,Set up the initial number whose smallest divisor we seek.,We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,Set up the initial number whose smallest divisor we seek.,We could initialize it to any positive integer greater than 1.,1 int num = 15;,Set up the initial number whose smallest divisor we seek.,"In this program, we initialize variable num to 15.",1 int divisor = 2;,Initialize the first possible smallest divisor,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,Initialize the first possible smallest divisor,We define variable divisor to store the smallest divisor of the number.,3 divisor += 1;,Go to the next possible smallest divisor,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",1 while (num % divisor != 0) {,Keep looking for a new divisor while the current divisor still leaves a remainder,"Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",1 while (num % divisor != 0) {,Keep looking for a new divisor while the current divisor still leaves a remainder,We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,3 while (num % divisor != 0) {,Keep looking for a new divisor while the current divisor still leaves a remainder,"Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,Keep looking for a new divisor while the current divisor still leaves a remainder,"The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",2 while (num % divisor != 0) {,Keep looking for a new divisor while the current divisor still leaves a remainder,We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",Print the number and the smallest divisor we found,This statement prints to the default standard output stream the smallest divisor of the number.,4 int num = 1234;,Initialize the number we seek to print in reverse,We need variable num to store the integer that we want to print its digits.,3 do {,Iterate through the whole number,We need to process the digits of the integer from right to left and print them.,2 do {,Iterate through the whole number,"Therefore, we need to use a loop structure.",1 do {,Iterate through the whole number,"In this program, we do this by using a do loop.",2 do {,Iterate through the whole number,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,1 System.out.println(num % 10);,Print the current digit in the ones place by finding the remainder of the number when dividing by ten,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,Print the current digit in the ones place by finding the remainder of the number when dividing by ten,We need to extract the last digit in the 1's position of the integer.,3 System.out.println(num % 10);,Print the current digit in the ones place by finding the remainder of the number when dividing by ten,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",3 System.out.println(num % 10);,Print the current digit in the ones place by finding the remainder of the number when dividing by ten,We do this by calculating the remainder of the division of the integer by 10.,3 System.out.println(num % 10);,Print the current digit in the ones place by finding the remainder of the number when dividing by ten,"Then, this statement prints the last digit of the integer to the standard output stream.",4 num = num / 10;,Remove the ones place on the number,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",2 num = num / 10;,Remove the ones place on the number,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,3 num = num / 10;,Remove the ones place on the number,Note that this statement performs an integer division because both operand of the / operator are integer.,1 } while (num > 0);,Break once we've removed all the digits in the number,We need to check for termination conditions to avoid infinite loops.,1 } while (num > 0);,Break once we've removed all the digits in the number,The loop should terminate when we run out of digits to process.,3 } while (num > 0);,Break once we've removed all the digits in the number,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",1 } while (num > 0);,Break once we've removed all the digits in the number,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",1 } while (num > 0);,Break once we've removed all the digits in the number,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,3 Scanner scan = new Scanner(System.in);,Set up a scanner to read in user inputs,"To read the input values from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,Set up a scanner to read in user inputs,We need to read and process the values that the user enters.,3 "System.out.println(""Enter the phone age in years:"");",Prompt the user to input the phone age,We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,Read in the user's input as an integer,We read the phone age by calling the nextInt() method because this input is an integer.,3 int phoneAge = scan.nextInt();,Read in the user's input as an integer,We need to read the phone age that the user enters and store it in a variable.,3 "System.out.println(""Enter whether the phone is broken (true or false):"");",Prompt the user to input whether the phone is broken or not,We prompt the user to enter whether the phone is broken.,4 boolean isBroken = scan.nextBoolean();,Read in the user's input as to whether the phone is broken,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,Read in the user's input as to whether the phone is broken,"The variable isBroken is true when the phone is broken, and false otherwise.",1 boolean isBroken = scan.nextBoolean();,Read in the user's input as to whether the phone is broken,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 scan.close();,Stop reading in user inputs,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 boolean needPhone = isBroken || phoneAge >= 3;,Find out if the phone is broken or if it is too old using the logical or operator,We use the || operator (called or) to combine the two conditions.,3 boolean needPhone = isBroken || phoneAge >= 3;,Find out if the phone is broken or if it is too old using the logical or operator,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,Find out if the phone is broken or if it is too old using the logical or operator,We need two conditions to determine if it is the time for a new phone.,3 System.out.println(needPhone);,Tell the user whether they need a new phone or not,This statement prints true/false depending on whether it is time to buy a new phone.,3 System.out.println(needPhone);,Tell the user whether they need a new phone or not,The printed value is followed by an end-of-line character in the end.,1 for (int num = 2; num <= 10; num += 2) {,Go through all even integers starting at two and ending at ten,"To do this, we need to use a loop structure.",1 for (int num = 2; num <= 10; num += 2) {,Go through all even integers starting at two and ending at ten,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,2 for (int num = 2; num <= 10; num += 2) {,Go through all even integers starting at two and ending at ten,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",3 for (int num = 2; num <= 10; num += 2) {,Go through all even integers starting at two and ending at ten,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,Go through all even integers starting at two and ending at ten,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",2 "System.out.println(num + "" squared = "" + (num * num));",Print out the square of the current even integer,The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));",Print out the square of the current even integer,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",Print out the square of the current even integer,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",1 "System.out.println(num + "" squared = "" + (num * num));",Print out the square of the current even integer,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",3 Point1 point = new Point1();,Generate an instance of the Point class,This statement creates a Point1 object using the new keyword and empty parentheses.,3 Point1 point = new Point1();,Generate an instance of the Point class,The variable point holds a reference to a Point1 object.,2 point.setX(7);,Set the x value in this point class,This statement invokes the method setX of the point to set its x-coordinate to 7.,3 "point.translate(11, 6);",Move the point by 11 in the x direction and 6 in the y direction,This statement invokes the method translate of the point.,2 "point.translate(11, 6);",Move the point by 11 in the x direction and 6 in the y direction,The second parameter specifies how much we want to shift the y-coordinate of the point.,2 "point.translate(11, 6);",Move the point by 11 in the x direction and 6 in the y direction,The translate method receives two parameters.,2 "point.translate(11, 6);",Move the point by 11 in the x direction and 6 in the y direction,The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the new coordinates of the point after translation by using the getters of the class,Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the new coordinates of the point after translation by using the getters of the class,We could use the returned value of them directly in the println statement.,2 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the new coordinates of the point after translation by using the getters of the class,This statement prints the coordinates of the point to the default standard output stream.,3 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the new coordinates of the point after translation by using the getters of the class,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;",Print out the new coordinates of the point after translation by using the getters of the class,"To get the point's coordinates, we invoke the method getX and getY of the point.",3 class Point1 {,Declare a new class called Point1,We define the class Point1 to represent a point in the Euclidean plane.,3 private int y;,Store the y value of the point,"Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",2 private int y;,Store the y value of the point,We declare it as integer because we want to have integer coordinates for the point.,1 private int y;,Store the y value of the point,"Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",1 private int y;,Store the y value of the point,Every object of the Point1 class will have its own y-coordinate.,2 "public void translate(int dx, int dy) {",Define a method for the class to translate the point by a certain amount in the x and y direction,"This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",3 "public void translate(int dx, int dy) {",Define a method for the class to translate the point by a certain amount in the x and y direction,We define this method as public to provide access to this method from outside of the class.,1 "public void translate(int dx, int dy) {",Define a method for the class to translate the point by a certain amount in the x and y direction,"Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {",Define a method for the class to translate the point by a certain amount in the x and y direction,Note that both of the parameters are declared as integers because the point has integer coordinates.,1 x += dx;,Move the point by the incoming dx value,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",3 x += dx;,Increment the point by the dx value,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",3 public void setX(int newX) {,Define a method to set a value for the point's x value,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,Define a method to set a value for the point's x value,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,Define a method to set a value for the point's x value,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,2 public void setX(int newX) {,Define a method to set a value for the point's x value,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,Define a method to set a value for the point's x value,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,Define a method to set a value for the point's x value,It can be changed from outside the class only through this method.,1 public int getX() {,Define a method to get the current x coordinate of the point,We define this method as public to provide access to this method from outside of the class.,2 public int getX() {,Define a method to get the current x coordinate of the point,This method returns the x-coordinate of the point.,2 public int getX() {,Define a method to get the current x coordinate of the point,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",2 public int getX() {,Define a method to get the current x coordinate of the point,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",2 public int getX() {,Define a method to get the current x coordinate of the point,It can be accessed from outside the class only through this getter method.,2 Scanner scan = new Scanner(System.in);,creates a new Scanner instance which points to the input stream passed as argument.,"To read the input value from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,creates a new Scanner instance which points to the input stream passed as argument.,We need to read and process the integer that the user enters.,1 "System.out.println(""Enter an integer: "");","this code line prints the text ""Enter an integer: """,We prompt the user to enter an integer.,5 int num = scan.nextInt();,This code line creates the integer called num and gives to it the value of the input number,We read the input integer by calling the nextInt() method because this input is an integer.,3 int num = scan.nextInt();,This code line creates the integer called num and gives to it the value of the input number,We need to read the integer that the user enters and store it in a variable.,3 if ( num > 0 ) {,"It's a if cycle, it does what is after the brace if the integer ""num"" is greater than 0","If the integer is neither positive nor negative, then we could conclude that the integer is zero.",1 if ( num > 0 ) {,"It's a if cycle, it does what is after the brace if the integer ""num"" is greater than 0","The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,"It's a if cycle, it does what is after the brace if the integer ""num"" is greater than 0","To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",1 if ( num > 0 ) {,"It's a if cycle, it does what is after the brace if the integer ""num"" is greater than 0","Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,"It's a if cycle, it does what is after the brace if the integer ""num"" is greater than 0","If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");","This code line prints the text ""The integer is positive.""",This statement prints that the integer is positive.,5 "System.out.println(""The integer is positivie."");","This code line prints the text ""The integer is positive.""",The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,"It's a else if statement. If the the integer ""num"" is smaller than 0 it does the instructions after the brace.","If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",2 "System.out.println(""The integer is negative."");","This code line prints the text ""The integer is negative.""",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");","This code line prints the text ""The integer is negative.""",This statement prints that the integer is negative.,5 } else {,"It's a else statement. If the integer ""num"" it's not greater or smaller than 0 (so it's equal to zero) it does the instructions after the brace.","We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",2 "System.out.println(""The integer is zero."");","This code line prints the text ""The integer is zero.""",The printed text is followed by the end-of-line character at the end.,2 "System.out.println(""The integer is zero."");","This code line prints the text ""The integer is zero.""",This statement prints that the integer is zero.,5 "System.out.println(""The integer is zero."");","This code line prints the text ""The integer is zero.""",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");","This code line prints the text ""The integer is zero.""",This statement prints that the integer is zero.,5 scan.close();,It closes this scanner.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 "int [] arr = { 1, 2, 3};",It declares an Array of integers.,We initialize the array of type int to hold the specified numbers.,3 "int [] arr = { 1, 2, 3};",It declares an Array of integers.,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,It's a for cycle.,We want to iterate over the array and increment each element in the array by 1.,1 for ( int i = 0; i < arr.length; i++ ) {,It's a for cycle.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,It's a for cycle.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,1 for ( int i = 0; i < arr.length; i++ ) {,It does the instructions after the brace as long as the integer i is smallar than the length of the array.,We want to iterate over the array and increment each element in the array by 1.,1 for ( int i = 0; i < arr.length; i++ ) {,It does the instructions after the brace as long as the integer i is smallar than the length of the array.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",1 for ( int i = 0; i < arr.length; i++ ) {,It does the instructions after the brace as long as the integer i is smallar than the length of the array.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,2 for ( int i = 0; i < arr.length; i++ ) {,After every cycle increment the value of i of 1.,We want to iterate over the array and increment each element in the array by 1.,4 for ( int i = 0; i < arr.length; i++ ) {,After every cycle increment the value of i of 1.,"To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,After every cycle increment the value of i of 1.,We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,3 arr[i] += 1;,Increment the value of the i-element of the array by 1.,This statement increments the element at the index i of the array by 1.,4 Scanner scan = new Scanner(System.in);,Creating a scanner variable that is used to take input from the user.,"To read the input value from the user, we need to define a Scanner object.",3 Scanner scan = new Scanner(System.in);,Creating a scanner variable that is used to take input from the user.,We need to read and process the value that the user enters.,4 "System.out.println(""Enter an integer for seconds: "");",Printing a prompt asking for user input,We prompt the user to enter the seconds.,5 int seconds = scan.nextInt();,Using the scanner variable created before to take input from user.,We need to read the seconds that the user enters and store it in a variable.,3 int seconds = scan.nextInt();,Using the scanner variable created before to take input from user.,We read the seconds by calling the nextInt() method because this input is an integer.,2 scan.close();,closing the scanner variable using the .close() method.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 int minutes = seconds / 60;,Converting the seconds to minutes by dividing by 60.,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",4 int minutes = seconds / 60;,Converting the seconds to minutes by dividing by 60.,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,The remaining seconds will be stored in integer variable by take modulus of 60.,This is because there are 60 seconds in a minute.,1 int remainingSeconds = seconds % 60;,The remaining seconds will be stored in integer variable by take modulus of 60.,Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,The remaining seconds will be stored in integer variable by take modulus of 60.,"To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Printing the final statement which includes time in seconds converted to minutes and seconds.,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,4 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Printing the final statement which includes time in seconds converted to minutes and seconds.,The printed text is followed by the end-of-line character at the end.,1 int num = 15;,Creating int variable num and assigning the value 15 to it.,We define variable num to store the number that we want to find its smallest divisor.,3 int num = 15;,Creating int variable num and assigning the value 15 to it.,We could initialize it to any positive integer greater than 1.,3 int num = 15;,Creating int variable num and assigning the value 15 to it.,"In this program, we initialize variable num to 15.",4 int divisor = 2;,Creating int variable divisor and assigning value 2 to it.,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,3 int divisor = 2;,Creating int variable divisor and assigning value 2 to it.,We define variable divisor to store the smallest divisor of the number.,2 while (num % divisor != 0) {,"Creating a while loop with the condition that while num modulus divisor is not equal to 0, the loop runs","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,"Creating a while loop with the condition that while num modulus divisor is not equal to 0, the loop runs",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,2 while (num % divisor != 0) {,"Creating a while loop with the condition that while num modulus divisor is not equal to 0, the loop runs","Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,"Creating a while loop with the condition that while num modulus divisor is not equal to 0, the loop runs","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",3 while (num % divisor != 0) {,"Creating a while loop with the condition that while num modulus divisor is not equal to 0, the loop runs",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,3 divisor += 1;,"Incrementing the divisor by 1 each time the loop runs. It is the same as divisor = divisor + 1","When the divisor is not a factor of the number, we increment the variable divisor by 1.",2 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",Printing out the final statement which prints the smallest divisor of the number.,This statement prints to the default standard output stream the smallest divisor of the number.,4 Scanner scan = new Scanner(System.in);,Creating a scanner variable to take user input.,"To read the input value from the user, we need to define a Scanner object.",5 Scanner scan = new Scanner(System.in);,Creating a scanner variable to take user input.,We need to read and process the integer that the user enters.,3 "System.out.println(""Enter an integer: "");",Prompt for the user to enter an integer.,We prompt the user to enter an integer.,5 int num = scan.nextInt();,Storing the value entered by user in int variable num,We read the input integer by calling the nextInt() method because this input is an integer.,2 int num = scan.nextInt();,Storing the value entered by user in int variable num,We need to read the integer that the user enters and store it in a variable.,3 scan.close();,Closing the scanner variable.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 if ( num > 0 ) {,Creating an if condition which is fulfilled if num > 0,"If the integer is neither positive nor negative, then we could conclude that the integer is zero.",1 if ( num > 0 ) {,Creating an if condition which is fulfilled if num > 0,"The conditions that tests for the integer's sign are mutually exclusive (i.e., one and only one of the conditions can be true); therefore, their order does not matter.",1 if ( num > 0 ) {,Creating an if condition which is fulfilled if num > 0,"To determine the sign of the integer, we need to perform two tests: one for determining whether the integer is positive and one for determining whether the integer is negative.",3 if ( num > 0 ) {,Creating an if condition which is fulfilled if num > 0,"Also, it is better to use if-else if statements instead of sequential if statements because an integer has only one sign and once we find the sign, we don't need to perform more tests.",1 if ( num > 0 ) {,Creating an if condition which is fulfilled if num > 0,"If both of these tests fail, then we could conclude that the integer is zero.",1 "System.out.println(""The integer is positivie."");",Printing a statement if the if condition is fulfilled.,This statement prints that the integer is positive.,2 "System.out.println(""The integer is positivie."");",Printing a statement if the if condition is fulfilled.,The printed text is followed by the end-of-line character at the end.,1 } else if ( num < 0 ) {,creating an else if condition which runs if num < 0,"If the first test fails (i.e., when the integer is not positive), we need to test if the integer is negative.",3 "System.out.println(""The integer is negative."");",Printing a statement when the else if condition is fulfilled.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is negative."");",Printing a statement when the else if condition is fulfilled.,This statement prints that the integer is negative.,2 } else {,"Creating an else condition which is fulfilled if neither if, or the else if conditions are met.","We need to end the above if-else if statements with an else statement that its body is executed when none of the above tests are true, that is when the integer is zero.",2 "System.out.println(""The integer is zero."");",Printing the statement if else condition is met.,The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The integer is zero."");",Printing the statement if else condition is met.,This statement prints that the integer is zero.,2 "int [] arr = { 1, 2, 3};","Creating an array arr which contains 3 elements 1, 2 and 3.",We initialize the array of type int to hold the specified numbers.,3 "int [] arr = { 1, 2, 3};","Creating an array arr which contains 3 elements 1, 2 and 3.",We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 for ( int i = 0; i < arr.length; i++ ) {,"Creating a for loop which runs the length of the array, in this case 3.",We want to iterate over the array and increment each element in the array by 1.,3 for ( int i = 0; i < arr.length; i++ ) {,"Creating a for loop which runs the length of the array, in this case 3.","To really change the array as we march across it, we need to use indexes so we can assign an updated value to each position as we go.",2 for ( int i = 0; i < arr.length; i++ ) {,"Creating a for loop which runs the length of the array, in this case 3.",We need the array indexes to start at 0 (array indexes start from 0) with every integer number up to but not including the array length.,2 arr[i] += 1;,The value of each number in the array is increased by 1.,This statement increments the element at the index i of the array by 1.,4 arr[i] += 1;,"For example, arr[0] = 1. But once the loop is run, it becomes arr[0] = arr[0] + 1 = 1 + 1 = 2.",This statement increments the element at the index i of the array by 1.,1 int num = 1234;,Creating int variable num with value 1234.,We need variable num to store the integer that we want to print its digits.,2 do {,Creating a do while loop,We need to process the digits of the integer from right to left and print them.,1 do {,Creating a do while loop,"Therefore, we need to use a loop structure.",2 do {,Creating a do while loop,"In this program, we do this by using a do loop.",2 do {,Creating a do while loop,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,1 num = num / 10;,Then the value of num is changed to num divided by 10.,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",1 num = num / 10;,Then the value of num is changed to num divided by 10.,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,3 num = num / 10;,Then the value of num is changed to num divided by 10.,Note that this statement performs an integer division because both operand of the / operator are integer.,3 System.out.println(num % 10);,Print num modulus 10,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,Print num modulus 10,We need to extract the last digit in the 1's position of the integer.,1 System.out.println(num % 10);,Print num modulus 10,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",1 System.out.println(num % 10);,Print num modulus 10,We do this by calculating the remainder of the division of the integer by 10.,3 System.out.println(num % 10);,Print num modulus 10,"Then, this statement prints the last digit of the integer to the standard output stream.",2 } while (num > 0);,Complete the do while loop using the condition num > 0.,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,Complete the do while loop using the condition num > 0.,The loop should terminate when we run out of digits to process.,2 } while (num > 0);,Complete the do while loop using the condition num > 0.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",3 } while (num > 0);,Complete the do while loop using the condition num > 0.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",3 } while (num > 0);,Complete the do while loop using the condition num > 0.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,2 } while (num > 0);,"This means that apart from the first time, the loop will only run if the num > 0",We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,"This means that apart from the first time, the loop will only run if the num > 0",The loop should terminate when we run out of digits to process.,2 } while (num > 0);,"This means that apart from the first time, the loop will only run if the num > 0","We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",3 } while (num > 0);,"This means that apart from the first time, the loop will only run if the num > 0","If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",2 } while (num > 0);,"This means that apart from the first time, the loop will only run if the num > 0",The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,3 Scanner scan = new Scanner(System.in);,Creating a scanner object called scan.,"To read the input values from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Creating a scanner object called scan.,We need to read and process the values that the user enters.,1 "System.out.println(""Enter the phone age in years:"");",Printing a statement to ask the user to enter the phone age in years.,We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,Storing the value entered by user in int variable phoneAge.,We read the phone age by calling the nextInt() method because this input is an integer.,2 int phoneAge = scan.nextInt();,Storing the value entered by user in int variable phoneAge.,We need to read the phone age that the user enters and store it in a variable.,3 "System.out.println(""Enter whether the phone is broken (true or false):"");",Asking the user to enter a true or false value about whether the phone is broken or not.,We prompt the user to enter whether the phone is broken.,4 boolean isBroken = scan.nextBoolean();,Storing the user input in a boolean variable isBroken.,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,Storing the user input in a boolean variable isBroken.,"The variable isBroken is true when the phone is broken, and false otherwise.",2 boolean isBroken = scan.nextBoolean();,Storing the user input in a boolean variable isBroken.,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 scan.close();,Closing the scanner object.,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 boolean needPhone = isBroken || phoneAge >= 3;,"Creating a boolean variable needPhone which is true if either the phone is broken, or the phone is 3 or more years old.",We use the || operator (called or) to combine the two conditions.,1 boolean needPhone = isBroken || phoneAge >= 3;,"Creating a boolean variable needPhone which is true if either the phone is broken, or the phone is 3 or more years old.",The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,"Creating a boolean variable needPhone which is true if either the phone is broken, or the phone is 3 or more years old.",We need two conditions to determine if it is the time for a new phone.,2 System.out.println(needPhone);,Printing the value of needPhone variable.,This statement prints true/false depending on whether it is time to buy a new phone.,2 System.out.println(needPhone);,Printing the value of needPhone variable.,The printed value is followed by an end-of-line character in the end.,1 "String fullName = ""John Smith""","Create a string variable and store the value ""John Smith"" in it.",We define a string variable to hold the name.,3 "String firstInitial = fullName.substring(0, 1);",Stores the value in the 1st position of the string fullName into another String firstInitial.,We need to extract the first letter from the first name.,2 "String firstInitial = fullName.substring(0, 1);",Stores the value in the 1st position of the string fullName into another String firstInitial.,"We do this by calling the substring(0,1) method.",3 "String lastInitial = fullName.substring(5, 6);",Stores the value of 6th position of the string fullName into another string lastInitial.,We need to extract the first letter from the last name.,2 "String lastInitial = fullName.substring(5, 6);",Stores the value of 6th position of the string fullName into another string lastInitial.,"We do this by calling the substring(5,6) method.",1 String initials = firstInitial + lastInitial;,"Creating a string initials which adds both the previous strings, firstInitial and lastinitial.",This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,Prints out the string initials.,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,Prints out the string initials.,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Creating an integer array with 5 values.,We define array values to hold the specified numbers.,3 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Creating an integer array with 5 values.,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 int maxValue = values[0];,Creating int variable maxValue and assigning the value of element in position 1 of the array values.,We need variable maxValue to store the maximum value of the array.,3 int maxValue = values[0];,Creating int variable maxValue and assigning the value of element in position 1 of the array values.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,3 for (int i = 1; i < values.length; i++) {,"Creating a for loop which runs 1 less than the size of the array values. In this case, the value of values.length is 5, so the loop will run 4 times.",We use a for loop to iterate over the remaining array indexes and search for the maximum value.,3 for (int i = 1; i < values.length; i++) {,"Creating a for loop which runs 1 less than the size of the array values. In this case, the value of values.length is 5, so the loop will run 4 times.",We need the array indexes to start at 1 with every integer number up to but not including the array length.,2 if (values[i] > maxValue) {,Creating if condition which is fulfilled if the values[i] is greated than the maxValue variable.,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,2 if (values[i] > maxValue) {,Creating if condition which is fulfilled if the values[i] is greated than the maxValue variable.,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",2 maxValue = values[i];,"If the if condition is fulfilled, the value of maxValue will be replaced by the value in values[i].",This statement sets the maximum value to value of the element at index i of the array.,3 "System.out.println(""Maximum value: "" + maxValue);",Statement to print the maximum value in the array values.,This statement prints the maximum value of the array to the default standard output stream.,4 Scanner scan = new Scanner(System.in);,Instance of object Scanner,"To read the input value from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Instance of object Scanner,We need to read and process the value that the user enters.,1 "System.out.println(""Enter an integer for seconds: "");",Print message on console,We prompt the user to enter the seconds.,2 int seconds = scan.nextInt();,Get input from command line as integer,We need to read the seconds that the user enters and store it in a variable.,2 int seconds = scan.nextInt();,Get input from command line as integer,We read the seconds by calling the nextInt() method because this input is an integer.,2 scan.close();,Close scanner instance,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 int minutes = seconds / 60;,calculate minutes by dividing by 60,"To obtain the minutes in seconds, we divide the seconds by 60 because there are 60 seconds in a minute.",3 int minutes = seconds / 60;,calculate minutes by dividing by 60,"Note that since both operands of division operator are integer, the fractional part of the result is truncated, if there is any.",1 int remainingSeconds = seconds % 60;,"calculate the seconds, making the modulus of the integer, to obtain the rest",This is because there are 60 seconds in a minute.,2 int remainingSeconds = seconds % 60;,"calculate the seconds, making the modulus of the integer, to obtain the rest",Note that the % operator returns the remainder of the division.,2 int remainingSeconds = seconds % 60;,"calculate the seconds, making the modulus of the integer, to obtain the rest","To obtain the remaining seconds after taking away the minutes, we have to take the remainder of the seconds divided by 60.",3 "System.out.println(""Enter an integer for seconds: "");",Print message by console so that the user inserts an integer number,We prompt the user to enter the seconds.,4 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Print message by console with the result separated by minutes and seconds,This statement prints to the default standard output stream the minutes and remaining seconds from the input amount of time in seconds.,4 "System.out.println(seconds + "" seconds is "" + minutes + "" minutes and "" + remainingSeconds + "" seconds."");",Print message by console with the result separated by minutes and seconds,The printed text is followed by the end-of-line character at the end.,1 int num = 15;,Integer variable declaration num,We define variable num to store the number that we want to find its smallest divisor.,2 int num = 15;,Integer variable declaration num,We could initialize it to any positive integer greater than 1.,2 int num = 15;,Integer variable declaration num,"In this program, we initialize variable num to 15.",2 int divisor = 2;,Integer variable declaration divisor,We initialize variable divisor by 2 because we want to find the smallest divisor except 1.,2 int divisor = 2;,Integer variable declaration divisor,We define variable divisor to store the smallest divisor of the number.,2 divisor += 1;,Fulfills the condition and we increase the divisor variable,"When the divisor is not a factor of the number, we increment the variable divisor by 1.",3 while (num % divisor != 0) {,"Loop condition, modulus between num and divisor","Since we don't know ahead of time how many times the loop will be repeated, we need to use a while loop.",2 while (num % divisor != 0) {,"Loop condition, modulus between num and divisor",We need to increment the divisor repeatedly as long as the divisor is not a factor of the number.,3 while (num % divisor != 0) {,"Loop condition, modulus between num and divisor","Therefore, we need to use a loop structure.",1 while (num % divisor != 0) {,"Loop condition, modulus between num and divisor","The condition in the while loop tests whether the body of the loop should be repeated, so it should test whether the divisor is not a factor of the number.",1 while (num % divisor != 0) {,"Loop condition, modulus between num and divisor",We could check whether the divisor is not a factor of the number by computing the remainder of the division of the number by the divisor.,2 "System.out.println(""The smallest divisor of "" + num + "" is "" + divisor);",Print message by console with the result of the smallest divisor of the variable num,This statement prints to the default standard output stream the smallest divisor of the number.,4 "String fullName = ""John Smith""",assign the value of John Smith to the string called fullName,We define a string variable to hold the name.,2 "String firstInitial = fullName.substring(0, 1);",Get the characters from position 0 to 1 of fullName and assign them to the firstInitial string,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",Get the characters from position 0 to 1 of fullName and assign them to the firstInitial string,"We do this by calling the substring(0,1) method.",3 "String lastInitial = fullName.substring(5, 6);",Get the characters from position 5 to 6 of fullName and assign them to the lastInitial string,We need to extract the first letter from the last name.,2 "String lastInitial = fullName.substring(5, 6);",Get the characters from position 5 to 6 of fullName and assign them to the lastInitial string,"We do this by calling the substring(5,6) method.",3 String initials = firstInitial + lastInitial;,Combine the first initial and the last initial and assign it to the initials string,This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,output the initials string,This statement prints the initials to the default standard output stream.,3 System.out.println(initials);,output the initials string,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",create an array with the values in the brackets,We define array values to hold the specified numbers.,3 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",create an array with the values in the brackets,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,4 int maxValue = values[0];,set the maxValue to the value at position 0 in the value array.,We need variable maxValue to store the maximum value of the array.,3 int maxValue = values[0];,set the maxValue to the value at position 0 in the value array.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,3 for (int i = 1; i < values.length; i++) {,"Loop through the array, from position 1 to the length of the array, incrementing by 1 position each time",We use a for loop to iterate over the remaining array indexes and search for the maximum value.,3 for (int i = 1; i < values.length; i++) {,"Loop through the array, from position 1 to the length of the array, incrementing by 1 position each time",We need the array indexes to start at 1 with every integer number up to but not including the array length.,3 if (values[i] > maxValue) {,check if the value at position i is greater than the maxValue,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,3 if (values[i] > maxValue) {,check if the value at position i is greater than the maxValue,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",3 maxValue = values[i];,"if the value is greater than the maxValue, assign that value to the maxValue",This statement sets the maximum value to value of the element at index i of the array.,3 "System.out.println(""Maximum value: "" + maxValue);",output the maxValue variable.,This statement prints the maximum value of the array to the default standard output stream.,3 int num = 1234;,to store integer type data. int helps in storing integer value into memory.,We need variable num to store the integer that we want to print its digits.,2 Scanner scan = new Scanner(System.in);,for obtaining the input of the int,"To read the input values from the user, we need to define a Scanner object.",1 Scanner scan = new Scanner(System.in);,for obtaining the input of the int,We need to read and process the values that the user enters.,1 "System.out.println(""Enter the phone age in years:"");",to print the sentence enclosed in the brackets display in the output screen,We prompt the user to enter the phone age in years.,1 int phoneAge = scan.nextInt();,to get the integer value and to store the int value in the integer memory,We read the phone age by calling the nextInt() method because this input is an integer.,2 int phoneAge = scan.nextInt();,to get the integer value and to store the int value in the integer memory,We need to read the phone age that the user enters and store it in a variable.,1 "System.out.println(""Enter whether the phone is broken (true or false):"");",to print the the sentence enclosed in the quotation display on the output screen,We prompt the user to enter whether the phone is broken.,1 boolean isBroken = scan.nextBoolean();,to boolean get the value 0 or 1 and store the value in the boolean memory,We need to read whether the phone is broken and store it in a variable.,1 boolean isBroken = scan.nextBoolean();,to boolean get the value 0 or 1 and store the value in the boolean memory,"The variable isBroken is true when the phone is broken, and false otherwise.",1 boolean isBroken = scan.nextBoolean();,to boolean get the value 0 or 1 and store the value in the boolean memory,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 scan.close();,to close the scanner,We close the scanner as we do not want to process any input from the user in the rest of the program.,2 boolean needPhone = isBroken || phoneAge >= 3;,to test the boolean value is true or not and store that in the needPhone memory,We use the || operator (called or) to combine the two conditions.,1 boolean needPhone = isBroken || phoneAge >= 3;,to test the boolean value is true or not and store that in the needPhone memory,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,2 boolean needPhone = isBroken || phoneAge >= 3;,to test the boolean value is true or not and store that in the needPhone memory,We need two conditions to determine if it is the time for a new phone.,2 System.out.println(needPhone);,print the needPhone value in the output screen,This statement prints true/false depending on whether it is time to buy a new phone.,2 System.out.println(needPhone);,print the needPhone value in the output screen,The printed value is followed by an end-of-line character in the end.,1 int num = 1234;,to store integer type data.,We need variable num to store the integer that we want to print its digits.,2 int num = 1234;,int helps in storing integer value into memory.,We need variable num to store the integer that we want to print its digits.,2 do {,its a loop used to process the values,We need to process the digits of the integer from right to left and print them.,2 do {,its a loop used to process the values,"Therefore, we need to use a loop structure.",2 do {,its a loop used to process the values,"In this program, we do this by using a do loop.",1 do {,its a loop used to process the values,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,1 num = num / 10;,formula to obtain the value of num,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",1 num = num / 10;,formula to obtain the value of num,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,1 num = num / 10;,formula to obtain the value of num,Note that this statement performs an integer division because both operand of the / operator are integer.,1 } while (num > 0);,end of the loop enclosed with condition,We need to check for termination conditions to avoid infinite loops.,3 } while (num > 0);,end of the loop enclosed with condition,The loop should terminate when we run out of digits to process.,2 } while (num > 0);,end of the loop enclosed with condition,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",1 } while (num > 0);,end of the loop enclosed with condition,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",1 } while (num > 0);,end of the loop enclosed with condition,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,1 System.out.println(num % 10);,print the num % 10 value in the output screen,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,print the num % 10 value in the output screen,We need to extract the last digit in the 1's position of the integer.,1 System.out.println(num % 10);,print the num % 10 value in the output screen,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",1 System.out.println(num % 10);,print the num % 10 value in the output screen,We do this by calculating the remainder of the division of the integer by 10.,4 System.out.println(num % 10);,print the num % 10 value in the output screen,"Then, this statement prints the last digit of the integer to the standard output stream.",1 "System.out.println(""Enter whether the phone is broken (true or false):"");",to print the sentence within the bracket opn oputput screen,We prompt the user to enter whether the phone is broken.,1 "System.out.println(""Enter whether the phone is broken (true or false):"");",ti print,We prompt the user to enter whether the phone is broken.,1 "String fullName = ""John Smith""",to store the name John smith in the String memory,We define a string variable to hold the name.,3 "String firstInitial = fullName.substring(0, 1);",getting the substring and store the data in firstInitial,We need to extract the first letter from the first name.,3 "String firstInitial = fullName.substring(0, 1);",getting the substring and store the data in firstInitial,"We do this by calling the substring(0,1) method.",2 String initials = firstInitial + lastInitial;,formula for join the firstInitial and lastInitial and store the answer in initials,This statements concatenates the extracted initials and store the result in the string initials.,4 "String lastInitial = fullName.substring(5, 6);",getting the substring and store the data in lastInitial,We need to extract the first letter from the last name.,3 "String lastInitial = fullName.substring(5, 6);",getting the substring and store the data in lastInitial,"We do this by calling the substring(5,6) method.",2 System.out.println(initials);,print the initials in the output screen,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,print the initials in the output screen,The printed value is followed by the end-of-line character at the end.,1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",store the array of integer values in the name values,We define array values to hold the specified numbers.,4 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",store the array of integer values in the name values,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 int maxValue = values[0];,initialize the array,We need variable maxValue to store the maximum value of the array.,1 int maxValue = values[0];,initialize the array,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,1 for (int i = 1; i < values.length; i++) {,condition enclosed in the for loop to obtain the maxValue in the array,We use a for loop to iterate over the remaining array indexes and search for the maximum value.,3 for (int i = 1; i < values.length; i++) {,condition enclosed in the for loop to obtain the maxValue in the array,We need the array indexes to start at 1 with every integer number up to but not including the array length.,1 if (values[i] > maxValue) {,check the condition whether it is true or not by finding the maxValue,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,2 if (values[i] > maxValue) {,check the condition whether it is true or not by finding the maxValue,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",1 maxValue = values[i];,store the biggest number in the maxValue,This statement sets the maximum value to value of the element at index i of the array.,3 "System.out.println(""Maximum value: "" + maxValue);",print the maxValue in the output screen,This statement prints the maximum value of the array to the default standard output stream.,4 if (values[i] > maxValue) {,check the condition whether its true or not,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,1 if (values[i] > maxValue) {,check the condition whether its true or not,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",1 int num = 1234;,Assign/initialize the number to be printed from left to right.,We need variable num to store the integer that we want to print its digits.,2 } while (num > 0);,Begin a loop while the number to printed is greater than 0.,We need to check for termination conditions to avoid infinite loops.,2 } while (num > 0);,Begin a loop while the number to printed is greater than 0.,The loop should terminate when we run out of digits to process.,2 } while (num > 0);,Begin a loop while the number to printed is greater than 0.,"We could check whether the are more digits left by checking whether the variable num, which gets updated in the body of the do loop, is greater than zero.",3 } while (num > 0);,Begin a loop while the number to printed is greater than 0.,"If variable num is greater than zero, then it must have at least one digit, and in that case, the body of the do loop will be repeated again.",2 } while (num > 0);,Begin a loop while the number to printed is greater than 0.,The body of the while loop should repeat as long as there are more digits left that we have not processed yet.,2 System.out.println(num % 10);,Print the remainder when divided by 10.,Each printed digit is followed by the line separator (e.g. '\n') at the end.,1 System.out.println(num % 10);,Print the remainder when divided by 10.,We need to extract the last digit in the 1's position of the integer.,2 System.out.println(num % 10);,Print the remainder when divided by 10.,"For example, if the integer is 1234, we want to extract the digit 4 that is in 1's position of the integer.",2 System.out.println(num % 10);,Print the remainder when divided by 10.,We do this by calculating the remainder of the division of the integer by 10.,3 System.out.println(num % 10);,Print the remainder when divided by 10.,"Then, this statement prints the last digit of the integer to the standard output stream.",2 num = num / 10;,Divide the initial number by 10,"Therefore, this division will remove the digit that we processed (lastDigit) and we can move on to the next digit.",2 num = num / 10;,Divide the initial number by 10,We truncate the extracted digit that we processed from the original integer by dividing the integer by 10.,3 num = num / 10;,Divide the initial number by 10,Note that this statement performs an integer division because both operand of the / operator are integer.,2 do {,Initiate the while loop.,We need to process the digits of the integer from right to left and print them.,1 do {,Initiate the while loop.,"Therefore, we need to use a loop structure.",2 do {,Initiate the while loop.,"In this program, we do this by using a do loop.",2 do {,Initiate the while loop.,The do loop is more appropriate than a while loop because a positive integer always has at least one digit which results in the body of the loop performing at least once.,1 Scanner scan = new Scanner(System.in);,Initialize the variable in which the user input will be scanned and stored.,"To read the input values from the user, we need to define a Scanner object.",2 Scanner scan = new Scanner(System.in);,Initialize the variable in which the user input will be scanned and stored.,We need to read and process the values that the user enters.,1 "System.out.println(""Enter the phone age in years:"");",Print the text asking the user to input the age of the phone in years.,We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,Scan the next token as an integer.,We read the phone age by calling the nextInt() method because this input is an integer.,2 int phoneAge = scan.nextInt();,Scan the next token as an integer.,We need to read the phone age that the user enters and store it in a variable.,2 "System.out.println(""Enter whether the phone is broken (true or false):"");",Print the text asking the user to enter whether the phone is broken or not.,We prompt the user to enter whether the phone is broken.,4 boolean isBroken = scan.nextBoolean();,Scan the next token of the user input for a boolean value and store it.,We need to read whether the phone is broken and store it in a variable.,3 boolean isBroken = scan.nextBoolean();,Scan the next token of the user input for a boolean value and store it.,"The variable isBroken is true when the phone is broken, and false otherwise.",1 boolean isBroken = scan.nextBoolean();,Scan the next token of the user input for a boolean value and store it.,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,3 int phoneAge = scan.nextInt();,Scan the next token as an integer and store it.,We read the phone age by calling the nextInt() method because this input is an integer.,3 int phoneAge = scan.nextInt();,Scan the next token as an integer and store it.,We need to read the phone age that the user enters and store it in a variable.,3 scan.close();,Close the scanner.,We close the scanner as we do not want to process any input from the user in the rest of the program.,3 boolean needPhone = isBroken || phoneAge >= 3;,Set boolean variable if the phone is broken or the phone age is greater than 3 years.,We use the || operator (called or) to combine the two conditions.,2 boolean needPhone = isBroken || phoneAge >= 3;,Set boolean variable if the phone is broken or the phone age is greater than 3 years.,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,Set boolean variable if the phone is broken or the phone age is greater than 3 years.,We need two conditions to determine if it is the time for a new phone.,1 System.out.println(needPhone);,Print whether new phone needs to be bought.,This statement prints true/false depending on whether it is time to buy a new phone.,3 System.out.println(needPhone);,Print whether new phone needs to be bought.,The printed value is followed by an end-of-line character in the end.,1 "String fullName = ""John Smith""",Initialize/assign the name whose initials should be printed.,We define a string variable to hold the name.,3 "String firstInitial = fullName.substring(0, 1);",Get the first letter of the first name (John).,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",Get the first letter of the first name (John).,"We do this by calling the substring(0,1) method.",1 "String lastInitial = fullName.substring(5, 6);",Get the first letter of the Last name(Smith).,We need to extract the first letter from the last name.,4 "String lastInitial = fullName.substring(5, 6);",Get the first letter of the Last name(Smith).,"We do this by calling the substring(5,6) method.",1 String initials = firstInitial + lastInitial;,Combine the first letter of the first name and the first letter of the last name.,This statements concatenates the extracted initials and store the result in the string initials.,4 System.out.println(initials);,Print the initials.,This statement prints the initials to the default standard output stream.,4 System.out.println(initials);,Print the initials.,The printed value is followed by the end-of-line character at the end.,1 "String firstInitial = fullName.substring(0, 1);",Get the first letter of the First name (John).,We need to extract the first letter from the first name.,4 "String firstInitial = fullName.substring(0, 1);",Get the first letter of the First name (John).,"We do this by calling the substring(0,1) method.",1 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Initialize the array containing the list of integers.,We define array values to hold the specified numbers.,3 "int[] values = {5, 8, 4, 78, 95, 12, 1, 0, 6, 35, 46};",Initialize the array containing the list of integers.,We initialize the array by separating elements with a comma and enclosing the collection in braces { }.,2 int maxValue = values[0];,Assume the first value in the array to be the maximum value and assign it to the variable.,We need variable maxValue to store the maximum value of the array.,1 int maxValue = values[0];,Assume the first value in the array to be the maximum value and assign it to the variable.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,4 for (int i = 1; i < values.length; i++) {,Initiate a for loop that loops over the elements of the array.,We use a for loop to iterate over the remaining array indexes and search for the maximum value.,3 for (int i = 1; i < values.length; i++) {,Initiate a for loop that loops over the elements of the array.,We need the array indexes to start at 1 with every integer number up to but not including the array length.,2 int maxValue = values[0];,Assume the first element of the array to be the maximum value and assign it to the variable.,We need variable maxValue to store the maximum value of the array.,2 int maxValue = values[0];,Assume the first element of the array to be the maximum value and assign it to the variable.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,4 if (values[i] > maxValue) {,"Check if the loop variable (element of the array) is greater than the previously assigned maximum value,",We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,3 if (values[i] > maxValue) {,"Check if the loop variable (element of the array) is greater than the previously assigned maximum value,","If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",3 maxValue = values[i];,"If so, assign the corresponding element to be the maximum value.",This statement sets the maximum value to value of the element at index i of the array.,2 "System.out.println(""Maximum value: "" + maxValue);",Print the maximum value of the array once all the elements of the array are looped over.,This statement prints the maximum value of the array to the default standard output stream.,4 int maxValue = values[0];,Assume the first element of the array to be the maximum value and assign it to the variable 'maxValue'.,We need variable maxValue to store the maximum value of the array.,2 int maxValue = values[0];,Assume the first element of the array to be the maximum value and assign it to the variable 'maxValue'.,We initialize this variable by the first value in the array because we initially assume that the first value is the maximum.,4 if (values[i] > maxValue) {,Check if the loop variable (element of the array) is greater than the previously assigned maximum value.,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,2 if (values[i] > maxValue) {,Check if the loop variable (element of the array) is greater than the previously assigned maximum value.,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",3 maxValue = values[i];,"If so, assign the corresponding element to be the maximum value.",This statement sets the maximum value to value of the element at index i of the array.,2 if (values[i] > maxValue) {,Check if the element of the array corresponding to the loop variable is greater than the previously assigned maximum value.,We need to compare the value at the index i of the array with the maximum value stored in variable maxValue.,2 if (values[i] > maxValue) {,Check if the element of the array corresponding to the loop variable is greater than the previously assigned maximum value.,"If the value at that index is larger than the maximum value, then we need to set the maximum value to the value of the element at index i.",2 for (int num = 2; num <= 10; num += 2) {,Initiate a for loop over the set of even positive integers less than or equal to 10.,"To do this, we need to use a loop structure.",2 for (int num = 2; num <= 10; num += 2) {,Initiate a for loop over the set of even positive integers less than or equal to 10.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,3 for (int num = 2; num <= 10; num += 2) {,Initiate a for loop over the set of even positive integers less than or equal to 10.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,Initiate a for loop over the set of even positive integers less than or equal to 10.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,Initiate a for loop over the set of even positive integers less than or equal to 10.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 "System.out.println(num + "" squared = "" + (num * num));",Print the the square of the number by multiplying the number with itself.,The multiplication may also be performed directly in the println statement.,3 "System.out.println(num + "" squared = "" + (num * num));",Print the the square of the number by multiplying the number with itself.,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",Print the the square of the number by multiplying the number with itself.,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",3 "System.out.println(num + "" squared = "" + (num * num));",Print the the square of the number by multiplying the number with itself.,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",2 Scanner scan = new Scanner(System.in);,initiate scanner class which is helpful in reading the input,"To read the input values from the user, we need to define a Scanner object.",4 Scanner scan = new Scanner(System.in);,initiate scanner class which is helpful in reading the input,We need to read and process the values that the user enters.,2 "System.out.println(""Enter the phone age in years:"");","print a prompt ""Enter the phone age in years"" into the console",We prompt the user to enter the phone age in years.,4 int phoneAge = scan.nextInt();,read the input from the console to variable phone age,We read the phone age by calling the nextInt() method because this input is an integer.,2 int phoneAge = scan.nextInt();,read the input from the console to variable phone age,We need to read the phone age that the user enters and store it in a variable.,2 "System.out.println(""Enter whether the phone is broken (true or false):"");","show a prompt on console ""Enter whether the phone is broken (true or false):""",We prompt the user to enter whether the phone is broken.,4 boolean isBroken = scan.nextBoolean();,read the input from the console onto variable isBroken,We need to read whether the phone is broken and store it in a variable.,2 boolean isBroken = scan.nextBoolean();,read the input from the console onto variable isBroken,"The variable isBroken is true when the phone is broken, and false otherwise.",2 boolean isBroken = scan.nextBoolean();,read the input from the console onto variable isBroken,We read whether the phone is broken by calling the nextBoolean() method because this input is a boolean.,2 scan.close();,closing the scanner class to end the process of reading the input from console,We close the scanner as we do not want to process any input from the user in the rest of the program.,4 boolean needPhone = isBroken || phoneAge >= 3;,check weather the phone is broken or phone age is greater than or equals to 3 then set the variable needPhone to TRUE,We use the || operator (called or) to combine the two conditions.,2 boolean needPhone = isBroken || phoneAge >= 3;,check weather the phone is broken or phone age is greater than or equals to 3 then set the variable needPhone to TRUE,The first condition is to test if the phone is broken and the second condition is to test if the phone age is at least 3 years old.,3 boolean needPhone = isBroken || phoneAge >= 3;,check weather the phone is broken or phone age is greater than or equals to 3 then set the variable needPhone to TRUE,We need two conditions to determine if it is the time for a new phone.,3 System.out.println(needPhone);,print the value of variable needPhone,This statement prints true/false depending on whether it is time to buy a new phone.,2 System.out.println(needPhone);,print the value of variable needPhone,The printed value is followed by an end-of-line character in the end.,1 for (int num = 2; num <= 10; num += 2) {,loop until the num value less than or equals to 10; start the num value at 2 and increment by 2 in each iteration,"To do this, we need to use a loop structure.",2 for (int num = 2; num <= 10; num += 2) {,loop until the num value less than or equals to 10; start the num value at 2 and increment by 2 in each iteration,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,3 for (int num = 2; num <= 10; num += 2) {,loop until the num value less than or equals to 10; start the num value at 2 and increment by 2 in each iteration,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",4 for (int num = 2; num <= 10; num += 2) {,loop until the num value less than or equals to 10; start the num value at 2 and increment by 2 in each iteration,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,loop until the num value less than or equals to 10; start the num value at 2 and increment by 2 in each iteration,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 "System.out.println(num + "" squared = "" + (num * num));",print square value of the num in the each iteration in the console,The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));",print square value of the num in the each iteration in the console,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",print square value of the num in the each iteration in the console,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",2 "System.out.println(num + "" squared = "" + (num * num));",print square value of the num in the each iteration in the console,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",4 Point1 point = new Point1();,initiate the class Point 1,This statement creates a Point1 object using the new keyword and empty parentheses.,2 Point1 point = new Point1();,initiate the class Point 1,The variable point holds a reference to a Point1 object.,2 point.setX(7);,call the setX method with parameter 7,This statement invokes the method setX of the point to set its x-coordinate to 7.,3 "point.translate(11, 6);","call translate method with variables 11, 6",This statement invokes the method translate of the point.,2 "point.translate(11, 6);","call translate method with variables 11, 6",The second parameter specifies how much we want to shift the y-coordinate of the point.,1 "point.translate(11, 6);","call translate method with variables 11, 6",The translate method receives two parameters.,2 "point.translate(11, 6);","call translate method with variables 11, 6",The first parameter specifies how much we want to shift the x-coordinate of the point.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","print the coordinates x,y using methods getX and getY",Note that we do not necessarily have to store the returned value from each of these methods in a variable.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","print the coordinates x,y using methods getX and getY",We could use the returned value of them directly in the println statement.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","print the coordinates x,y using methods getX and getY",This statement prints the coordinates of the point to the default standard output stream.,3 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","print the coordinates x,y using methods getX and getY",The printed text is followed by the end-of-line character at the end.,1 "System.out.println(""The point's coordinates: ("" + point.getX() + "", "" + point.getY() + "")"") ;","print the coordinates x,y using methods getX and getY","To get the point's coordinates, we invoke the method getX and getY of the point.",3 class Point1 {,class Point 1 definition start,We define the class Point1 to represent a point in the Euclidean plane.,3 private int y;,declare the variable y,"Therefore, we need to declare an instance variable for the class to store the y-coordinate of the point.",2 private int y;,declare the variable y,We declare it as integer because we want to have integer coordinates for the point.,1 private int y;,declare the variable y,"Note that an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance.",1 private int y;,declare the variable y,Every object of the Point1 class will have its own y-coordinate.,1 "public void translate(int dx, int dy) {",translate method definition,"This method shifts the coordinates by a specific delta-x and delta-y, which are passed as parameters.",2 "public void translate(int dx, int dy) {",translate method definition,We define this method as public to provide access to this method from outside of the class.,1 "public void translate(int dx, int dy) {",translate method definition,"Also, we define its return type as void, as it does not return any value.",1 "public void translate(int dx, int dy) {",translate method definition,Note that both of the parameters are declared as integers because the point has integer coordinates.,1 x += dx;,X=X+dx,"To shift the x-coordinate of the point, we need to add dx to the value of the x-coordinate of the point.",3 public void setX(int newX) {,setX method definition,"Also, we define its return type as void, as it does not return any value.",1 public void setX(int newX) {,setX method definition,We define this method as public to provide access to this method from outside of the class.,1 public void setX(int newX) {,setX method definition,This method sets the current value of the x-coordinate of the point to the given value (newX) that is specified as the method's parameter.,2 public void setX(int newX) {,setX method definition,"Note that the instance variable x is private; thus, it cannot be directly changed from outside the class.",1 public void setX(int newX) {,setX method definition,The parameter of the method is declared as integer because the x-coordinate of the point is an integer.,1 public void setX(int newX) {,setX method definition,It can be changed from outside the class only through this method.,1 public int getX() {,getX method definition,We define this method as public to provide access to this method from outside of the class.,2 public int getX() {,getX method definition,This method returns the x-coordinate of the point.,2 public int getX() {,getX method definition,"Note that the instance variable x is private; thus, it cannot be directly accessed from outside the class.",1 public int getX() {,getX method definition,"Also, we define its return type as int, as it returns the x-coordinate of the point which is an integer.",1 public int getX() {,getX method definition,It can be accessed from outside the class only through this getter method.,2 for (int num = 2; num <= 10; num += 2) {,"line 3 starts the ""for"" loop.","To do this, we need to use a loop structure.",3 for (int num = 2; num <= 10; num += 2) {,"line 3 starts the ""for"" loop.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,1 for (int num = 2; num <= 10; num += 2) {,"line 3 starts the ""for"" loop.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",1 for (int num = 2; num <= 10; num += 2) {,"line 3 starts the ""for"" loop.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,"line 3 starts the ""for"" loop.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",2 for (int num = 2; num <= 10; num += 2) {,"As the goal states we have to obtain the square of every even number that is lower than 10, the loop starts with 2.","To do this, we need to use a loop structure.",2 for (int num = 2; num <= 10; num += 2) {,"As the goal states we have to obtain the square of every even number that is lower than 10, the loop starts with 2.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,2 for (int num = 2; num <= 10; num += 2) {,"As the goal states we have to obtain the square of every even number that is lower than 10, the loop starts with 2.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,"As the goal states we have to obtain the square of every even number that is lower than 10, the loop starts with 2.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",2 for (int num = 2; num <= 10; num += 2) {,"As the goal states we have to obtain the square of every even number that is lower than 10, the loop starts with 2.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",3 for (int num = 2; num <= 10; num += 2) {,"it is incremented by 2 every time, so we get the next even number.","To do this, we need to use a loop structure.",1 for (int num = 2; num <= 10; num += 2) {,"it is incremented by 2 every time, so we get the next even number.",We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,2 for (int num = 2; num <= 10; num += 2) {,"it is incremented by 2 every time, so we get the next even number.","To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,"it is incremented by 2 every time, so we get the next even number.","We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,"it is incremented by 2 every time, so we get the next even number.","Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",2 for (int num = 2; num <= 10; num += 2) {,Num<= 10 condition is to get numbers that are lesser than or equal to 10.,"To do this, we need to use a loop structure.",1 for (int num = 2; num <= 10; num += 2) {,Num<= 10 condition is to get numbers that are lesser than or equal to 10.,We need to repeat the same process for each of the even positive integers that are less than or equal to 10.,2 for (int num = 2; num <= 10; num += 2) {,Num<= 10 condition is to get numbers that are lesser than or equal to 10.,"To do this, we initialize variable num to 2, loop until reaching 10 (inclusive), and increment num by 2 after each iteration of the loop.",2 for (int num = 2; num <= 10; num += 2) {,Num<= 10 condition is to get numbers that are lesser than or equal to 10.,"We use for loops instead of a while loop because we need to repeat the loop a certain number of times, and for loops are best-suited in cases like this when we know ahead of time the number of times that we need to repeat the loop.",1 for (int num = 2; num <= 10; num += 2) {,Num<= 10 condition is to get numbers that are lesser than or equal to 10.,"Here, we want the for loop to start counting from 2 (2 is the first positive even number) with every even integer number up to (including) 10.",2 "System.out.println(num + "" squared = "" + (num * num));",line 4 is just to print the output.,The multiplication may also be performed directly in the println statement.,1 "System.out.println(num + "" squared = "" + (num * num));",line 4 is just to print the output.,Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));",line 4 is just to print the output.,"To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",1 "System.out.println(num + "" squared = "" + (num * num));",line 4 is just to print the output.,"In each iteration of the loop, this statement prints the square number to the default standard output stream.",1 "System.out.println(num + "" squared = "" + (num * num));","Every-time the next even number will taken, it will printed and the with the formula of ""num*num"" its square will be obtained and printed.",The multiplication may also be performed directly in the println statement.,2 "System.out.println(num + "" squared = "" + (num * num));","Every-time the next even number will taken, it will printed and the with the formula of ""num*num"" its square will be obtained and printed.",Note that we do not necessarily have to store the squared number in a variable.,1 "System.out.println(num + "" squared = "" + (num * num));","Every-time the next even number will taken, it will printed and the with the formula of ""num*num"" its square will be obtained and printed.","To square each number in the sequence, we multiply it by itself using the multiplication (*) operator.",3 "System.out.println(num + "" squared = "" + (num * num));","Every-time the next even number will taken, it will printed and the with the formula of ""num*num"" its square will be obtained and printed.","In each iteration of the loop, this statement prints the square number to the default standard output stream.",3 Point1 point = new Point1();,"Line 3 is just a declaration of a new object of type ""Point1"".",This statement creates a Point1 object using the new keyword and empty parentheses.,3 Point1 point = new Point1();,"Line 3 is just a declaration of a new object of type ""Point1"".",The variable point holds a reference to a Point1 object.,2 point.setX(7);,"By using the function setX, the value 7 is passed to the object.",This statement invokes the method setX of the point to set its x-coordinate to 7.,3 point.setX(7);,It will be an x-coordinate.,This statement invokes the method setX of the point to set its x-coordinate to 7.,1 "point.translate(11, 6);","With the function ""translate"", the x and y co-ordinates of the point will be moved to 11 and 6 respectively.",This statement invokes the method translate of the point.,3 "point.translate(11, 6);","With the function ""translate"", the x and y co-ordinates of the point will be moved to 11 and 6 respectively.",The second parameter specifies how much we want to shift the y-coordinate of the point.,1 "point.translate(11, 6);","With the function ""translate"", the x and y co-ordinates of the point will be moved to 11 and 6 respectively.",The first parameter specifies how much we want to shift the x-coordinate of the point.,2 "point.translate(11, 6);","With the function ""translate"", the x and y co-ordinates of the point will be moved to 11 and 6 respectively.",The translate method receives two parameters.,1 ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,, ,,,