This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please send me the answer

 
praveen kumar tummala
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class hai
{
public static void main(String[] args)
{
for(int i=1;i<3;i++)
{
System.out.println("Hello World!");
}
if(int i<5)
{
System.out.println("hello");
i++;
}
}
}


I want the answer with out intialising i globally or reinitialising would you do that
[ March 03, 2006: Message edited by: praveen kumar tummala ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your question, I think you want to declare int i within the scope of the main method. Then remove the initialization statement from the for "loop" (so that you don't have a separate int i within the loop), and change the "if" statement to a "while"...

Note: Please use Code Tags...

http://faq.javaranch.com/view?UseCodeTags
[ March 03, 2006: Message edited by: marc weber ]
 
praveen kumar tummala
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int i = 1;


I dont want to initialise seperately,i would like to use "i" in for loop,by using that "i" variable in if, i want the answer,


thanks for ur response
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by praveen kumar tummala:
... I dont want to initialise seperately,i would like to use "i" in for loop,by using that "i" variable in if, i want the answer...

Then the answer is: You can't. A variable is limited to the scope in which it's declared. So if you declare int i in the "for" loop, then that variable's scope is limited to the "for" loop.
[ March 03, 2006: Message edited by: marc weber ]
 
praveen kumar tummala
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic