Click here to Skip to main content
15,914,071 members
Home / Discussions / Java
   

Java

 
AnswerRe: Problem with ArrayLists java Pin
Richard MacCutchan21-Jan-12 23:05
mveRichard MacCutchan21-Jan-12 23:05 
QuestionHelp with adding jPanel Form to other form Pin
_T("No name")21-Jan-12 5:53
_T("No name")21-Jan-12 5:53 
AnswerRe: Help with adding jPanel Form to other form Pin
TorstenH.22-Jan-12 21:42
TorstenH.22-Jan-12 21:42 
QuestionMultithreaded proxy server Pin
prateek.rajan8919-Jan-12 16:29
prateek.rajan8919-Jan-12 16:29 
AnswerRe: Multithreaded proxy server Pin
Peter_in_278019-Jan-12 17:41
professionalPeter_in_278019-Jan-12 17:41 
AnswerRe: Multithreaded proxy server Pin
jschell20-Jan-12 12:49
jschell20-Jan-12 12:49 
Questioncode problem Pin
nikhil_kumar19-Jan-12 11:04
nikhil_kumar19-Jan-12 11:04 
AnswerRe: code problem Pin
TorstenH.19-Jan-12 21:34
TorstenH.19-Jan-12 21:34 
Java
class Code1{
  public static void main(String[] args) {
    int[] a = new int[20];
    int i=0;
    while(i<20) {
      a[i] = i;
      System.out.println(a[i]);
      i++;
    }
  }
}


Java
class Code2{
  public static void main(String[] args) {
    int[] a = new int[20];
    int i=0;
    while(i<20) {
      a[i] = i;
      i++;
      System.out.println(a[i]);
 
    }
  }
}


That fit's better to my display, which is more wide than high Wink | ;) Also check the renaming of the classes

Code1 increments the value i after the value of a[i] is print out.
Therefor each value of a[] is set and print out different.

in Code2 the Array a[] is initialized. That set's all values of a[] to "0".
After that you set a value of a[] and increment i before print out.
So you get in the print out the next value - which is still "0" and you exceed the limit of the array in the endposition (you try to print a[20], but the array goes from 0-19 ).

That's why.
regards Torsten
When I'm not working

GeneralRe: code problem Pin
nikhil_kumar21-Jan-12 9:10
nikhil_kumar21-Jan-12 9:10 
GeneralRe: code problem Pin
♥…ЯҠ…♥12-Feb-12 17:41
professional♥…ЯҠ…♥12-Feb-12 17:41 
AnswerRe: code problem Pin
♥…ЯҠ…♥12-Feb-12 17:14
professional♥…ЯҠ…♥12-Feb-12 17:14 
Questionsource code Pin
bhanu.pratap.9918-Jan-12 2:46
bhanu.pratap.9918-Jan-12 2:46 
AnswerRe: source code Pin
Richard MacCutchan18-Jan-12 3:00
mveRichard MacCutchan18-Jan-12 3:00 
AnswerRe: source code Pin
Nagy Vilmos18-Jan-12 3:03
professionalNagy Vilmos18-Jan-12 3:03 
AnswerRe: source code Pin
TorstenH.18-Jan-12 3:23
TorstenH.18-Jan-12 3:23 
AnswerRe: source code Pin
SilimSayo26-Jan-12 6:49
SilimSayo26-Jan-12 6:49 
QuestionHow to write a program in java which stores every thing i type anywhere in a file Pin
anilgoyal128915-Jan-12 18:25
anilgoyal128915-Jan-12 18:25 
AnswerRe: How to write a program in java which stores every thing i type anywhere in a file Pin
Richard MacCutchan15-Jan-12 21:28
mveRichard MacCutchan15-Jan-12 21:28 
AnswerRe: How to write a program in java which stores every thing i type anywhere in a file Pin
TorstenH.15-Jan-12 21:30
TorstenH.15-Jan-12 21:30 
GeneralRe: How to write a program in java which stores every thing i type anywhere in a file Pin
anilgoyal128919-Jan-12 19:53
anilgoyal128919-Jan-12 19:53 
GeneralRe: How to write a program in java which stores every thing i type anywhere in a file Pin
TorstenH.23-Jan-12 19:34
TorstenH.23-Jan-12 19:34 
AnswerRe: How to write a program in java which stores every thing i type anywhere in a file Pin
Nagy Vilmos18-Jan-12 3:05
professionalNagy Vilmos18-Jan-12 3:05 
GeneralRe: How to write a program in java which stores every thing i type anywhere in a file Pin
TorstenH.18-Jan-12 3:22
TorstenH.18-Jan-12 3:22 
GeneralRe: How to write a program in java which stores every thing i type anywhere in a file Pin
anilgoyal128919-Jan-12 19:50
anilgoyal128919-Jan-12 19:50 
Questionremain application in the running when i exit it Pin
ZAliPour13-Jan-12 1:15
ZAliPour13-Jan-12 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.