java_fundamentals icon indicating copy to clipboard operation
java_fundamentals copied to clipboard

I need java source code about how to use: for, do-while, and while

Open xaca opened this issue 8 years ago • 10 comments
trafficstars

Would be nice have challenges about loops in java or code with some problem solved.

xaca avatar Sep 27 '17 21:09 xaca

For-Loop Example:

for (int i = 0; i < 10; i++) {
    System.out.println(i);
}

Do-While-Loop Example

do {
    // Your code
} while (condition);

While-Loop Example

while(condition) {
    // Your code
}

Hope i could help you. Happy Hacktoberfest.

V1ncNet avatar Sep 27 '17 22:09 V1ncNet

@V1ncNet Thanks for your contributions, in the slides we have the documentation about hout to use the loops, but we need more examples and more ploblems to solve or solven in code.

xaca avatar Sep 27 '17 22:09 xaca

Hi, I would like to do this!

tombiju avatar Sep 27 '17 22:09 tombiju

Hi, When I started out learning a programming language for the first time I remember the following problems being vital in understanding and applying loops effectively. As a learning exercise the student should implement all the questions using all types of loops available in the language.

  1. Write a main method that will read in integers until a negative value is entered, and displays the sum of all of the non-negative value that had been entered.
  2. Print the patterns (n = 5 in this example, make n as user input)
*
**
***
****
*****
  1. Print a pyramid pattern of *'s. Number of rows in the pyramid could be a user input.
  2. Print pascals triangle given n (user input)
  3. Find the reverse of a given number n
  4. Print the following pattern
*****
****
***
**
*

Let me know if these questions work. If yes, I'll code the solutions and post them here.

Cheers!

AdityaAS avatar Sep 27 '17 23:09 AdityaAS

@tombiju We are waiting for your help! @AdityaAS thank you, good problems. I like to update each folder, with the exercises. so we need more help. I'll publish more issues.

xaca avatar Sep 28 '17 00:09 xaca

@xaca Could you tell me how I should go about organizing the solutions. I was thinking for each problem I'll defined a method in the files "ForLoop.java" and "WhileLoop.java" and call them from the main function. Does that work?

AdityaAS avatar Sep 30 '17 01:09 AdityaAS

@AdityaAS Yes, this aproach is good. Each class could have a main method, or share a same main. Is your call.

xaca avatar Sep 30 '17 03:09 xaca

@xaca I would like to add a Program related to oops as well. Do tell me if you want that. The question is of multiplication, addition and subtraction of polynomials using oops.

ribhav-pahuja avatar Oct 01 '17 11:10 ribhav-pahuja

@ribhav-pahuja Course this program is important, please contribute.

xaca avatar Oct 01 '17 14:10 xaca

@xaca Will surely add what I fell like is important for this course. Thanks

ribhav-pahuja avatar Oct 01 '17 14:10 ribhav-pahuja