File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes local varaible doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "local varaible doubt" Watch "local varaible doubt" New topic
Author

local varaible doubt

pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
for(int i=0;i<4;i++)
for(int j=0;j<5;j++){
twod[i][j]=k;
k++;
}
for(int i=0;i<4;i++)
for(int j=0;j<5;j++){
System.out.print(twod[i][j] + " ");

}
/*******doubt******************/
1> It is said that in java we cant declare local variable with same name in same or enclosing scope.
2> But the above code works fine even though INT i and INT j are declared twice?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

With a little reformatting for clarity, isn't this what you have?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

they are not in the same scope. each version of i and j fall out of scope when the for-loop where it is defined ends.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: local varaible doubt
 
Similar Threads
Label control doubt??
The shift >> doubt .......................
Arrays of Arrays
Array initialisation doubt.
Two Dimensional Array Question