This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Features new in Java 7 and the fly likes two arrays are there if we  are using single for look we can read two indexes one forward direction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "two arrays are there if we  are using single for look we can read two indexes one forward direction " Watch "two arrays are there if we  are using single for look we can read two indexes one forward direction " New topic
Author

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

krishnamurthy durgam
Greenhorn

Joined: Sep 10, 2012
Posts: 13

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

Joined: Oct 13, 2005
Posts: 37900
    
  22
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?
 
Consider Paul's rocket mass heater.
 
subject: two arrays are there if we are using single for look we can read two indexes one forward direction
 
Similar Threads
Using enhanced for loop to iterate in reverse order ?
Displaying an image from byte[] into JSP
confused abut Enhanced For loop
Transfer Multiple File problems via socket
How to give Servlet response from Tag Handler class?