The cycle for does not work for me [closed]

1

For some reason the cycles for does not work for me in eclipse luna, update the jdk but it's still the same, this is the simple code

public class main {

public static void main(String[] arg) {
    System.out.println("inicio");
    for(int i = 0; i > 10; i++) {
        System.out.println("Numer: " + i);
    }
}}

for some reason it does not work, it's as if the for did not exist, it just happens to me with that and it's very weird.

    
asked by Oscar Dali 02.10.2018 в 07:00
source

4 answers

2

I'm 99% sure that the problem is in the condition. I do not speak in java but I think the condition is permanent in the cycle. That is to say     i

answered by 02.10.2018 / 07:07
source
4

You have a series of errors that I mention below

  • The variable i of the cycle for must be less than 10 and you are indicating it is greater that will not allow it to run or start the bucle for
  • Your code should look like this

  • The condition must be <= 10 so that the number 10 is also printed, otherwise if you only put < 10 you will only print up to 9
  • FUNCTIONAL CODE

    public class main {
    
    public static void main(String args[]) {
        System.out.println("inicio");
        for(int i = 0; i <= 10; i++) {
            System.out.println("Numer: " + i);
        }
    }}
    
        
    answered by 02.10.2018 в 07:08
    2

    is because of the condition you put, your counter i never meets the greater than 10, if you want to iterate 10 times:

    for( i = 0; i < 10; i++) { ... }
    

    in this way the condition is met 10 times

        
    answered by 02.10.2018 в 07:06
    0

    It's not that it does not work. I think you already answered it before, but where you are wrong is in your conditional. Since you have an initial value of "0" but in your condition it says that i should be worth ">" 10, then that's where you're wrong. It should be <="10".

    class main
    {
        public static void main(String[] args){
            System.out.print("inicio");
            for(int i =0; i<=10; i++)
                System.out.print("\nTu numero" + i);
        }
    }
    
        
    answered by 02.10.2018 в 16:18