About 4,980,000 results
Open links in new tab
  1. java - How to use a for loop with an if-else statement - Stack Overflow

    Here is the code I have: public static void main(String[] args) for(int i = 55; i <= 100 ; i++) System.out.println("Student's score is: " + i + . "\tStudent's grade is " + getGrade(i)); public static double getGrade(int score) double grade = 0.0; if(score < 60 && score > 0) return grade = 0.0; else if (score >= 60 && score <= 62)

  2. java - Check if string contains a character with for loop

    Apr 2, 2017 · I am currently working on a simple code that will check if an user inputted String contains character(s) that are specified in the for loop. My current code. import java.util.Scanner; public class AutumnLeaves { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int G = 0; int R = 0; int Y = 0; int B = 0; String S ...

  3. Run a for loop until the String Condition in JAVA

    Jan 14, 2014 · for(j = i; !name[j].contains(" ---- "); j++){ . keywords = keywords + name[j]; That should work for you, you can set the break condition of a for loop to be any boolean expression. Edit: Need the ! in there as loop breaks when condition is false. Any reason that you use contains instead of equals ?

  4. Loops and Strings | Think Java | Trinket

    In this chapter, you’ll learn how to use while and for loops to add repetition to your code. We’ll also take a first look at String methods and solve some interesting problems. Using a while statement, we can repeat the same code multiple times: int n = 3; while (n > 0) { System.out.println (n); n = n - 1; } System.out.println ("Blastoff!");

  5. Java For Loop - W3Schools

    When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop: Syntax for ( statement 1 ; statement 2 ; statement 3 ) { // code block to be executed }

  6. Java For Loop - GeeksforGeeks

    Apr 17, 2025 · Java for loop is a control flow statement that allows code to be executed repeatedly based on a given condition. The for loop in Java provides an efficient way to iterate over a range of values, execute code multiple times, or traverse arrays and collections. Now let's go through a simple Java for l

  7. For loop in Java with example - BeginnersBook

    Sep 11, 2022 · For loop is used to execute a set of statements repeatedly until a particular condition returns false. In Java we have three types of basic loops: for, while and do-while. In this tutorial you will learn about for loop in Java. You will also learn nested for loop, enhanced for loop and infinite for loop

  8. Java For Loop Example - freeCodeCamp.org

    Feb 7, 2023 · In this article, we'll focus on the for loop, its syntax, and some examples to help you use it in your code. The for loop is mostly used when you know the number of times a loop is expected to run before stopping. Here's what the syntax of for loop in …

  9. 4.3. Loops and Strings — CS Java - runestone.academy

    Loops are often used for String Traversals or String Processing where the code steps through a string character by character. In lesson 2.6 and 2.7, we learned to use String objects and built-in string methods to process strings. In this lesson, we will write our own loops to process strings.

  10. Java For Loop - Baeldung

    Feb 16, 2025 · In this article, we’ll look at a core aspect of the Java language – executing a statement or a group of statements repeatedly using a for loop. 2. Simple for Loop. A for loop is a control structure that allows us to repeat certain operations …

  11. Some results have been removed
Refresh