Search:

Type: Posts; User: BenjaminJ

Search: Search took 0.09 seconds.

  1. Re: Print variable which only exists within for loop?

    int[] onetoTen = {1,2,3,4,5,6,7,8,9,10};
    int sum = 0;

    for (int i=0; i<10; i++) {



    sum +=onetoTen[0]++;
    System.out.println(sum);
  2. Re: Print variable which only exists within for loop?

    Okay, thank you both that worked fine, does that mean that it needs to be declared in main only? I tried it in main and that worked, but would it work if it were to be declared in another method?
    ...
  3. Print variable which only exists within for loop?

    There's loads of problems with this. What I'm trying to do.

    1) get a program to add the contents of an array together, preferably with a for loop and not the heavy handed version I've tried to...
Results 1 to 3 of 3