• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 13
Hibernate Java ME Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic