File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two arrays are there if we are using single for look we can read two indexes one forward direction

 
krishnamurthy durgam
Greenhorn
Posts: 13
Hibernate Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another one is back ward direction. when two indexes are equal program will be terminated how can achieve this?
I wrote some peace of code in that not enter into if condition it is allways false how can you make it as true?

public class ArraysTest {
public static void main(String args[])

{
int a[]={1,2,3,4,5,6,7,8,9,10};
int b[]={1,2,3,4,5,6,7,8,9,10};
int len=b.length-1;
for(int i=0;i<a.length;i++){
if(i==len){
System.out.println("hello");
break;
}
System.out.println(a[i]);
System.out.println(b[len]);
len--;
}

please help me>
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please go back to your code and use the button to add code tags, and change the indentation. You have inconsistent indentation, which means you will not be able to see yourself where all the pairs of {} belong, nor whether they are correctly matched.
Go through the code with a pencil, or add some debugging print statements. Try System.out.printf("a[%d] = %d, len = %d%n", i, a[i], len); at the beginning of your loop. Copy that line by hand, not ctrl-C, because it has &nbsp; characters in. Then you can see what is happening in the loop.
What does len-- at the end do?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic