Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to Java
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Bookmark and Share
Lecture Comments (10)

1 answer

Last reply by: Professor Quayle
Fri Oct 2, 2015 12:25 AM

Post by Malik Hall on September 23, 2015

Hi Professor Quayle,
I saw an example in a textbook that I did not understand about loops. This example showed SENTINELs, DecimalFormat, Scanners, and the highlighted word new. Could you explain these to me please because I have a difficult time understanding these in class since my teacher uses SENTINELs and Scanners in his examples.

1 answer

Last reply by: Professor Quayle
Tue Mar 11, 2014 12:19 AM

Post by Zelong Zhao on March 9, 2014

well, all of questions above are very cool.

I still cannot understand what means of "break" and "returen"
What should I do?
I am not a english native speaker, so which book should I read. PS: In my personal dictionary, "understand" means I know What is it && Why we need it.
For example, What is the logic form of Break and Returen? Why Java includes those.

I know those are big questions and even do not be included in AP Subscribes but I really want to try to know those.

It is honor to get your lessons.

1 answer

Last reply by: Professor Quayle
Tue Nov 19, 2013 12:03 AM

Post by Ashna Ayub on November 17, 2013

Professor Quayle,

I have been able understand how to write a for loop in terms of syntax, but I don't really understand how to read the code which is why I am stuck on this problem:

Consider the following array:

int[] a = { 1,2,3,4,5,4,3,2,1, 0 }

What is the value of total after the following loops complete? (by looking at the for loop)

int total = 0;
for (int i = 0; i < 10 ; i = i +2 ) {total = total + a[i]; }

Could you please explain how to find the total by looking at the loop?

1 answer

Last reply by: Professor Quayle
Sat Oct 13, 2012 10:11 AM

Post by William Gould on October 13, 2012

Dr Quayle,

I am doing an assignment that doesn't seem to be working and i wanted to ask if you could help me understand whats going on.
my assignment is to develop a new class called MathTasks and create a method called productFor, productWhile, and productDoWhile that has a strictly positive integer parameter n and computes and returns the product of all the integers from 1 to n (inclusive of n).

here is my code so far (its very messy so far because im brand new to coding)

public class MathTasks
public MathTasks()
{ }
public void productFor(int n) {
for (int i = 1; (1 > 0) && (i <= n); i++)
System.out.print (n * 1);
System.out.print ("n = " + n);
} }
public void productWhile(int n)
while ((1 > 0) && (i <= n)){
System.out.print (n * 1);
System.out.print ("n = " + n);
public void productDoWhile (int n) {
if (n > 0) {
do {
System.out.print(n * 1);
System.out.print("n = " + n); }
while ((1 > 0) && (i <= n));
} }

Could you help explain to me how this works and what i am doing wrong?

1 answer

Last reply by: Malik Hall
Fri Sep 18, 2015 10:09 PM

Post by Brad Cherry on September 17, 2012

I am currently doing something like this and I am just beginning to understand this but I am still a bit lost, I use JCreator java program and I go with my class and I am stressed out and over worked any way I can keep up we get homework every Monday and it is due the next Tuesday and we get more than a few programs to make and that for me is too much pressure since I have little java experience


  • The while loop repeats an action 0 or more times as long as a condition is true
  • The do-while loop repeats an action 1 or more times (not in AP subset)
  • The for loop repeats an action a specified number of times
  • The enhanced for loop repeats an action one time for each item in a collection
  • While, do-while, and for loops can be nested as many levels deep as desired


Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Roadmap 0:07
  • Repeating an Action 0:53
    • Example
  • Repeating an Action 1:21
    • Use Brute Force Method
  • The While Loop 2:16
    • To Repeat An Action
    • Example: While Loop
  • The Do Loop 5:53
    • Example: Do Loop
    • Distinction of Do Loop & While Loop
  • The For Loop 10:30
    • The Way It Works
    • Example: The For Loop
  • The Enhanced for Loop 14:18
    • The Way It Works
    • Example:Enhanced for Loop
  • Nested While Loops 19:06
    • Example
    • Example: Nested While Loop (Code)
  • Nested For Loops 22:36
    • Example
    • Example: Nested For Loop (Code)
  • The Return Statement 24:30
    • Example
  • The Break Statement 26:21
  • The Continue Statement 28:01
  • Summary 30:56