# Introduction to Java Loops

Section 1: AP Computer Science: Lecture 6 | 32:29 min

Lecture Description

In this lesson, our instructor Tom Quayle goes through an introduction on loops. He starts by discussing repeating an action, the while loop, do loop and for loop. He then goes on to talk about enhanced for loop, nested while loops and nested for loops. H

Tom Quayle

Loops

Slide Duration:Table of Contents

Section 1: AP Computer Science

About the AP Computer Science Exam

17m 11s

- Intro0:00
- Roadmap0:16
- Java Editor0:45
- The AP Computer Science Exam1:30
- When It's Administered1:31
- Final Score1:49
- College Credit2:08
- Format of AP Exam Questions2:20
- Two Sections2:26
- Section 12:31
- Section 22:40
- Scoring3:23
- Multiple Choice Questions3:57
- Example4:04
- Check Answer in Java Editor5:06
- Keep in Mind6:21
- Multiple Choice, Multiple Answers6:58
- Evaluate Each Roman Numeral Separately7:08
- Example Multiple Choice Question7:34
- Java Editor8:35
- Free Response Questions12:25
- Example12:40
- Java Editor14:35
- AP Java Subset17:06
- What It Is17:37
- Primitive Types18:49
- Arithmetic Operators19:11
- Assignment Operator19:46
- Combined Arithmetic / Assignment Operators19:51
- Increment / Decrement Operators20:13
- Relational Operators20:36
- Logical Operators21:06
- Numeric Casts21:44
- Numeric Wrapper Classes22:39
- Math Library Methods23:08
- String Operations23:50
- User Input25:33
- Output27:17
- Program Invocation28:13
- Arrays29:06
- Lists29:52
- Control Structures30:47
- Methods31:27
- Classes32:10
- Inheritance33:09
- Exceptions34:22
- Tips for Taking the Exam34:55
- Before the Exam35:04
- During the Exam36:58
- Summary39:27

Types, Variables, & Arithmetic Operators

23m 20s

- Intro0:00
- Roadmap0:11
- Primitive Data Types0:37
- Int1:48
- Double2:42
- Boolean3:53
- Variables4:04
- Declaring a Variable4:16
- Assigning a Value6:01
- Declaring and Assigning on the Same Line6:36
- Casting7:00
- Mixing Types7:10
- Automatic Casting8:31
- Find Variables - Constants9:21
- Final Variables9:40
- Constants Written in All Capitals10:43
- Arithmetic Operators11:59
- Five Arithmetic Operators12:10
- Result Depends on Type of Operands13:49
- Assignment Operators14:59
- Compound Assignment Operators15:13
- Examples15:43
- Increment / Decrement Operators17:08
- Add 1 (++)17:37
- Subtracts 1 (--)18:25
- Summary21:41

Equality, Relational, & Logical Operators

22m 34s

- Intro0:00
- Roadmap0:11
- Equality and Relational Operators1:09
- Equal to1:15
- Not Equal to2:25
- Relational Operators2:40
- Logical Operators3:44
- Three Operators: And, Or, Not3:53
- AND Defined4:18
- OR Defined4:50
- NOT Defined5:19
- Example: And5:43
- Example: Or6:23
- Example: Not6:41
- Truth Tables7:16
- Truth Tables for AND7:30
- Truth Tables for OR8:05
- Truth Tables for NOT8:47
- Short-Circuit Evaluation10:03
- Example10:32
- This Behavior Can be Useful in Program Design12:29
- De Morgan's Laws13:53
- First Law14:04
- Second Law14:29
- Operator Precedence15:28
- List of Operators in Highest to Lowest Precedence15:38
- Evaluation on Operators17:30
- Summary20:26

Input, Output, & Errors

24m 7s

- Intro0:00
- Roadmap0:11
- Getting Input from the User0:42
- For AP Questions, Will Look Like One of the Following0:54
- One Method of Getting Input From the User2:50
- Scanner Class3:20
- Providing Output to the User4:38
- Only 2 Included in AP Subset5:06
- Example: Print Two Strings on the Same Line5:45
- Example: Print a String and an Integer6:16
- Example: Print a Blank Line6:40
- Java Code Example7:04
- Escape Sequences11:10
- Backslash Character Followed by One or More Additional Characters11:23
- Newline Character11:49
- Double Quote Character12:39
- Backslash Character13:48
- Java Code Examples: Printing Escape Sequences14:43
- Exception Handling16:25
- Describe As16:33
- Exceptions Within the AP Subset That Provides Structured Way to Handle Errors17:18
- Java Code Example19:40
- Summary22:21

Conditional Statements

28m

- Intro0:00
- Roadmap0:09
- Conditional Statements0:55
- Based on Value of a Boolean Expression1:40
- Switch Statement2:42
- The If Statement2:59
- Structure of If Statement3:06
- The If-Else Statement4:46
- The If-Else Statement6:02
- If expression - False6:34
- Nested If-Else Statements7:13
- 'Nest'7:28
- Nested If-Else Statements7:56
- First Thing to Determine9:28
- Code10:24
- The Extended If Statement13:14
- Code15:45
- The Switch Statement18:54
- The Way It Works19:37
- Example: Switch Statement in a Java Program22:44
- Summary27:03

Loops

32m 29s

- Intro0:00
- Roadmap0:07
- Repeating an Action0:53
- Example1:03
- Repeating an Action1:21
- Use Brute Force Method1:32
- The While Loop2:16
- To Repeat An Action2:55
- Example: While Loop4:57
- The Do Loop5:53
- Example: Do Loop8:00
- Distinction of Do Loop & While Loop9:04
- The For Loop10:30
- The Way It Works10:41
- Example: The For Loop12:43
- The Enhanced for Loop14:18
- The Way It Works14:42
- Example:Enhanced for Loop16:32
- Nested While Loops19:06
- Example19:33
- Example: Nested While Loop (Code)20:47
- Nested For Loops22:36
- Example22:51
- Example: Nested For Loop (Code)23:29
- The Return Statement24:30
- Example25:03
- The Break Statement26:21
- The Continue Statement28:01
- Summary30:56

Strings

42m 20s

- Intro0:00
- Roadmap0:25
- Literal Strings1:27
- Class: Strings1:38
- String Is Immutable2:11
- Example2:53
- Literal Strings3:27
- String Variables4:24
- Example: String Variable5:56
- String Concatenation7:03
- Example7:37
- Example: String Concatenation8:26
- String Concatenation10:00
- Assignment Operator10:11
- Example10:48
- Example: String Concatenation11:25
- String Length13:05
- Example: String Length14:16
- String Comparison16:04
- Equals Method16:37
- Example: String Comparison17:08
- String Comparison21:40
- String.Equals: Case-Sensitive21:49
- Equals Ignore Case: Case-Insensitive22:14
- Example: Case-Sensitive and Case-Insensitive Comparison22:46
- String Comparison25:38
- Compare To (String.compareTo)25:53
- Example27:27
- Example: Sting Comparison Using the compareTo Method28:15
- Taking a Subset of a String30:34
- Substring Method30:59
- 2 Versions31:08
- 1st Version: Takes One Parameter31:27
- 2nd Version: Takes Two Parameters32:41
- Example: Substring34:02
- Searching Within a String36:04
- indexOf Method36:12
- 1st Version: Takes One Parameter36:26
- 2nd Version: Takes Two Parameters37:27
- Searching Within a String38:36
- lastIndexOf Method38:53
- 1st Version: Takes One Parameter39:08
- 2nd Version: Takes Two Parameters39:28
- Summary40:43

Arrays

47m 2s

- Intro0:00
- Roadmap0:14
- Declaring and Creating an Array0:49
- Array Defined0:55
- 1st Way to Declare and Create and Array1:10
- 2nd Way to Declare and Create and Array2:15
- Referring to Elements in an Array5:12
- Integer Expression5:39
- Code Example: Declaring and Creating Arrays7:26
- Referring to Elements in an Array9:12
- Example9:45
- Code Example: Looping Through an Array of Ints12:23
- Referring to Elements in an Array15:35
- Enhanced for Loop15:42
- Code Example: Looping Through an Array of Strings With an Enhanced for Loop17:19
- Referring to Elements in an Array19:25
- ArrayIndexOutOfBoundsException19:37
- Code Example: Array Index Out of Bounds Exception21:03
- Resizing Arrays23:05
- Example23:33
- Code Example: Resizing Arrays25:15
- Copying Arrays28:13
- Passing an Array to a Method30:09
- Example30:15
- When Calling This Method: Pass in an Array33:40
- Code Example: Passing an Array to a Method34:06
- Returning an Array From a Method36:02
- Create a Method36:12
- Calling This Method38:42
- Code Example: Returning an Array to a Method39:24
- Two-Dimensional Arrays42:23
- Length Method43:17
- Number of Columns43:42
- Summary45:00

Classes & Objects

47m 33s

- Intro0:00
- Roadmap0:46
- Classes and Objects2:03
- Class2:17
- Object2:34
- Constructors3:43
- Constructors5:34
- Methods7:11
- Example: getName Method7:44
- Methods8:45
- Example9:08
- Example in Java Program10:19
- Data Fields12:48
- Way to Find Data Fields13:10
- Data Fields13:50
- Example: Instantiate Two Objects with Different Instance Data14:43
- Return Type16:21
- A Primitive Type16:37
- An Object of a Class Type16:49
- Return Type17:25
- Access Control18:19
- Public, Protected and Private19:31
- Assumptions Made in AP Java Subset20:00
- Access Control20:58
- Definition of Public21:08
- Definition of Protected21:18
- Definition of Private21:28
- Guidelines on What to Make Public/ Private21:36
- Accessors and Modifiers24:47
- Accessor25:35
- Modifier or Mutator26:24
- Static vs. Instance27:15
- Static Member27:26
- Example: Static vs. Instance27:59
- Code Example30:19
- Passing Data to Method34:00
- Code Example36:17
- Getting Data Back From Methods37:28
- To Make Use of a Return Value37:53
- Code Example38:51
- Overloaded Methods39:39
- Signature Includes40:19
- Signature Does Not Include40:45
- Example: Overloaded Methods43:52
- Overloaded Methods44:19
- Summary45:00

Inheritance & Polymorphism

31m 30s

- Intro0:00
- Roadmap0:42
- Inheritance1:14
- Subclass1:56
- Superclass2:07
- Inheritance3:08
- Example3:36
- Inheritance4:44
- Subclass Does Not Inherit…6:05
- Inheritance7:06
- To Override a Method7:17
- Inheritance8:59
- Example10:24
- Class Hierarchies11:31
- Multiple Level Hierarchies for Subclass12:41
- Abstract Classes14:35
- Example15:59
- Polymorphism20:19
- Example20:34
- Interfaces22:33
- Interfaces Example25:13
- Defines 3 Methods25:27
- Summary29:26

Lists

33m 15s

- Intro0:00
- Roadmap0:16
- Lists0:52
- Wrapper Classes1:10
- The List Interface2:37
- Cannot Instantiate a List3:26
- The ArrayList Class5:01
- The Way It Works7:45
- The ArrayList Class8:34
- Primary Methods Needed To Use for ArraryList8:53
- Code Examples16:26
- The LinkedList Class21:01
- To Instantiate a LinkedList…21:59
- Code Example24:05
- ArrayList vs. LinkedList25:25
- Internal Storage Implementation of ArrayList25:35
- Internal Storage Implementation of LinkedList26:01
- Pros/Cons of Each26:23
- Summary32:10

Numeric Wrapper Classes & Mathematical Functions

23m 14s

- Intro0:00
- Roadmap0:11
- Numeric Wrapper Classes0:42
- To Get Around Storing Limitation1:19
- Setting and Getting Values2:30
- Double Class3:57
- Comparing Values5:07
- Equals Method5:22
- Comparing Values7:16
- CompareTo Method: Integer Class7:29
- CompareTo Method: Double Class9:24
- Minimum and Maximum Values10:28
- Integer Class: Publib Static Final10:56
- Double Class12:19
- Automatic Conversion12:53
- Autoboxing13:12
- Example13:36
- Get Method14:52
- The Math Class15:59
- Math.E16:18
- Math.PI16:25
- Example16:34
- The Math Class17:07
- Working With Random Numbers18:42
- Example19:47
- Summary22:14

Algorithms: Iteration

25m 43s

- Intro0:00
- Roadmap0:13
- Iteration0:36
- Iteration Defined0:39
- For Loop / While Loop0:50
- Example1:11
- Iteration3:11
- Two-Dimensional Range3:19
- Using Two Nested While Loops5:00
- Finding Minimum and Maximum Values5:54
- Finding Minimum and Maximum Values Examples7:50
- Finding Minimum and Maximum Values Example12:52
- Inserting in Order15:19
- Inserting in Order Code17:42
- Loop Invariants21:53
- Example23:17
- Summary24:37

Algorithms: Recursion

27m 30s

- Intro0:00
- Roadmap0:09
- Recursion0:44
- Calculating Factorials2:49
- n! and How It's Defined3:01
- Recursive Implementation of the Factorial Function in Java3:34
- Calculating Factorials4:34
- Calculate 4!4:35
- Factorial Function in Java7:22
- Calculating Fibonacci Numbers9:19
- Fibonacci Numbers Defined9:30
- Recursive Implementation10:33
- Implementation in Java10:44
- Calculating Fibonacci Numbers11:28
- Calculate Fibonacci(4)11:29
- Fibonacci in Java14:59
- Other Recursive Functions17:35
- Other Recursive Functions21:32
- Calculate Mystery(4)21:33
- Mystery in Java22:29
- Important Considerations23:49
- Recursive Methods25:15
- Summary26:41

Algorithms: Sorting

29m 42s

- Intro0:00
- Roadmap0:08
- Sorting0:55
- Definition of Sorting1:05
- Cant Sort Any of the Following1:14
- Selection Sort3:49
- Definition of Selection Sort3:58
- 'Search-and-Swap' Algorithm5:05
- Selection Sort Example7:46
- Insertion Sort10:57
- Insertion Sort Example13:02
- Merge Sort15:14
- Recursive Sorting Algorithm16:15
- Merge Sort Example18:03
- Quick Sort20:34
- Recursive Sorting Algorithm21:36
- Quick Sort Example23:35
- Summary27:19

Algorithms: Searching

32m 37s

- Intro0:00
- Roadmap0:08
- Searching0:40
- Sequential Search2:22
- Performed on Any Array2:29
- Sequential Search Algorithm Using a For Loop4:24
- Java Example6:28
- Binary Search8:51
- Binary Search Algorithm Using a While Loop12:03
- Java Example16:59
- Binary Search20:38
- Recursive Method20:53
- Java Example: Using Binary Search25:34
- Search Considerations28:16
- Binary Search29:14
- Summary31:14

Program Design & Development

29m 29s

- Intro0:00
- Roadmap0:41
- Object-Oriented Programming1:20
- Definition1:35
- Encapsulation2:26
- Polymorphism4:43
- Top-Down Design and Development5:56
- Top-Down Design6:10
- Top-Down Development6:51
- Reusable Code8:47
- Definition8:58
- Example to Reusable Code10:33
- Team Development11:36
- Team Development15:03
- Adding Another Developer15:23
- Data Structure19:28
- Definition19:35
- Examples19:44
- User Interface20:53
- Definition21:00
- Specifications24:19
- Definition24:29
- 2 Important Purposes for Specifications25:25
- Summary27:27

Standard Classes & Interfaces

32m 53s

- Intro0:00
- Roadmap0:13
- Object1:46
- Methods1:57
- Equals Method2:06
- toString Method2:16
- What Else To Know2:28
- Integer3:19
- Constructor3:32
- Methods3:51
- Constants4:28
- What Else To Know5:05
- Double6:14
- Constructor6:35
- Methods6:50
- What Else To Know7:06
- String8:16
- Methods8:40
- What Else To Know12:10
- Math15:24
- Methods15:36
- What Else To Know18:13
- List20:02
- Methods20:30
- ArrayList22:45
- What Else To Know23:27
- Test-Taking Tips26:05
- Summary29:47

Section 2: AP Test Preparation

Multiple Choice Question Tips & Practice

55m 47s

- Intro0:00
- Roadmap0:23
- AP Computer Science Exam Structure1:32
- Two Sections1:40
- Contribution to Score3:35
- Multiple Choice Strategies and Tips4:50
- Example Question 19:07
- Example Question 213:34
- Example Question 316:12
- Example Question 421:44
- Example Question 526:41
- Example Question 634:12
- Example Question 739:41
- Example Question 842:09
- Example Question 946:31
- Example Question 1050:35
- Summary54:49

Free Response Question Tips & Practice

40m 55s

- Intro0:00
- Roadmap0:27
- AP Computer Science Exam Structure1:15
- Two Sections1:20
- Contribution to Score2:09
- Free Response Strategies and Tips3:23
- Free Response Strategies and Tips Continued6:17
- Free Response Strategies and Tips Continued10:22
- Free Response Strategies and Tips Continued13:00
- Free Response Strategies and Tips Continued15:42
- Example Free Response Question17:41
- Example Free Response Question Narrative Continued18:30
- Example for Problem19:29
- Example Set-Up for Problem19:56
- Example Set-Up for Problem Continued21:48
- Code24:14
- Code Continued: First Method25:36
- Second Method26:28
- Additional Narrative27:04
- Definition of Part A: What They Want You to Write27:33
- Definition of Part B: What They Want You to Write28:50
- Requirements for Part A31:06
- Part A: One Possible Solution31:49
- Requirements for Part B34:06
- Part B: One Possible Solution34:48
- Summary39:52

The GridWorld Study

54m 18s

- Intro0:00
- Roadmap0:19
- Overview of GridWorld0:51
- Definition of GridWorld1:00
- Important part of AP Exam3:14
- Need to Understand It5:16
- Overview of GridWorld: Testable APIs8:00
- API Defined8:06
- Testable APIs8:52
- Testable Code9:22
- 4 Classes9:57
- Location Class10:21
- Location Class: 8 Public Constants That Help with Direction11:36
- Row Numbering12:32
- Column Numbering13:13
- Location Class: 7 Public Constants That Represent Turns13:31
- Location Class: Methods Useful in Navigating Through the Grid15:25
- getAdjacentLocation15:34
- getDirectionToward16:21
- Location Class: 3 Other Useful Methods16:58
- Equals Method17:05
- CompareTo Method17:35
- ToString Method18:16
- Grid Interface18:41
- Represents18:50
- Grid Interface: Useful Methods20:34
- getNumRows Method20:42
- getNumCols Method20:52
- isValid Method21:00
- Grid Interface: Useful Methods22:16
- Put Method22:23
- Remove Method22:13
- Get Method23:26
- Grid Interface: Useful Methods23:44
- GetOccupiedLocations Method23:55
- GetValidAdjacentLocations Method24:21
- GetEmptyAdjacentLocations Method25:02
- GetOccupiedAdjacentLocations Method25:24
- Grid Interface: Useful Methods25:37
- GetNeighbors Method25:44
- Actor Class26:27
- Constuctor: Actor27:02
- GetColor Method27:31
- SetColor Method27:38
- GetDirectionToward Method27:46
- SetDirection Method28:09
- GetGrid Method28:27
- GetLocation Method28:40
- PutSelfInGrid and RemoveSelfFromGrid Method28:51
- MoveTo Method30:03
- Act Method30:17
- ToString Method31:24
- Rock Class31:46
- 3 Methods31:58
- Flower Class32:35
- 3 Methods32:51
- Bug Class33:53
- Includes These Methods34:34
- How the Move Method Works36:38
- CanMove Method38:53
- BoxBug Class40:49
- Behavior41:00
- 2 Private Variables41:20
- Constructor for BoxBug41:55
- BoxBug Class Methods42:16
- Critter Class43:41
- How It Works44:03
- Next Step45:38
- 3rd Step47:01
- Last Step in Act Method48:33
- ChameleonCritter Class49:00
- Redefines Some Characteristics of Critter Class49:26
- Another Difference51:02
- Summary52:25

Multiple Choice Questions About GridWorld

41m

- Intro0:00
- Roadmap0:16
- Multiple Choice Strategies and Tips0:45
- Structure0:49
- Points Worth1:47
- Some Strategies and Tips3:29
- No Penalty for Wrong Answer6:10
- Some Strategies and Tips Specifically on GridWorld Questions6:29
- Some Strategies and Tips Specifically on GridWorld Questions9:37
- GridWorld Testable APIs and Code13:17
- Testable APIs13:25
- Testable Code13:47
- Example Question 114:32
- Example Question 217:11
- Example Question 322:53
- Example Question 426:17
- Example Question 534:11
- Summary39:47

Free Response Questions About GridWorld

39m 31s

- Intro0:00
- Roadmap0:14
- Free Response Strategies and Tips0:49
- Format0:56
- Points1:18
- Quick Reference Guide1:49
- Not Required to Do in Order2:48
- Multiple Parts3:33
- All Answers Must Be Written in Java5:00
- Partially Correct Solutions Can Be Awarded Partial Credit7:49
- Write Neatly10:40
- Don't Waste Time12:52
- GridWorld Testable APIs and Code14:55
- Testable APIs15:05
- Testable Code15:53
- GridWorld Testable APIs and Code16:37
- GridWorld Free Response Question16:41
- Example17:34
- Example Free Response Question18:23
- Question18:54
- Visual Diagram of the Game Board20:00
- Visual Chart21:08
- Narration Continues21:56
- The Piece Class22:59
- Narration Continues23:59
- What You Will Need to Do24:28
- The Rest of the Definition for DropGame25:08
- Part A: Requirements25:55
- Part B: Requirements28:44
- Part A: Question (Again)31:54
- Part A: One Possible Solution32:19
- Part B: Question (Again)35:30
- Part B: One Possible Solution35:47
- Summary38:34

Final Tips for Taking the Exam

27m 38s

- Intro0:00
- Roadmap0:10
- AP Computer Science Exam Structure0:46
- Two Sections0:49
- Scoring1:24
- Multiple Choice Strategies and Tips2:15
- Answer Questions for Descriptive Paragraph First2:38
- No Penalty for Wrong Answer3:42
- Free Response Strategies and Tips4:00
- Each Part Graded Separately4:57
- All Answers Written in Java5:54
- Partially Correct Solutions8:32
- Write Neatly10:33
- Draw a Single Line Through Mess-Ups13:09
- Additional Resources14:49
- Download the Project Files for GridWorld15:20
- Download Reference Documents15:39
- Remember, You Can Watch This Lesson More Than Once15:54
- What to Bring to Your Exam16:19
- What Not to Bring to Your Exam18:47
- The Night Before Your Exam22:00
- The Day of Your Exam24:23
- Summary26:44

Glossary of Terms to Know

36m 31s

- Intro0:00
- Roadmap0:16
- Abstract Class1:28
- Array2:29
- Casting3:43
- Class4:39
- Conditional Statement5:35
- Constructor6:28
- Escape Sequence7:18
- Exception8:24
- Final Variable8:59
- Inheritance10:19
- Instance11:36
- Interface12:33
- Iteration13:08
- List14:05
- Logical Operator15:11
- Loop16:20
- Loop Invariant17:06
- Method17:30
- Numeric Wrapper Class18:55
- Overloading20:38
- Polymorphism21:10
- Primitive Data Type23:22
- Public and Private24:06
- Random25:03
- Recursion27:07
- Return Type28:08
- Searching28:59
- Signature30:14
- Sorting30:51
- Static32:40
- String33:37
- Subclass and Superclass34:30
- Glossary35:37

Loading...

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

For more information, please see full course syllabus of Introduction to Java

Next Lecture

Previous Lecture

0 answers

Post by Basit Khan on January 16, 2017

Dr. Quayle,

after attending the java loops, I had a following exercise to solve;

In one of the introductory courses in a university, passing students are assigned a final grade of the uppercase letter P or lowercase p while failing students are assigned the letter F or f. Write a Java program that asks the user to enter grades (P/p or F/f) for 30 students, then calculates and displays both percentages of the passing and failing students.

I tried to solve it but to be honest I struggle to apply the syntax and formula. My main issue is that after reading and listening to the lecture I'm not able to apply it to create a program, kindly Help!

thanks

Omair

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.

https://drive.google.com/file/d/0B4eQm5IOB_khdFRFQTVFTUlZaTQ/view?usp=sharing

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