• 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

can anybody explain the program?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;
public class VecNum
{
Hi iam unble to understand the below program.can anybody explain the program flow?i will be thankful if anybody helps me out.

Thanks,
satya

public static void main(String argv[])
{
Vector v = new Vector();
v.add(new Integer(1));
v.add(new Integer(2));
for(int i=0; i < v.size();i ++)
{
Integer iw =(Integer) v.get(i);
System.out.println(iw.intValue());
}
}
}
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you still using J1.4? They haven't told you to put the class name after the word Vector?

Put a "System.out.println" statement after every line, and get it to print
  • Vector v = new Vector();
  • v.add(new Integer(1));
  • etc etc
  • , then you can follow the execution of the program.
     
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It's a very simple program that creates a Vector, adds two numbers to the vector, and then in a loop prints all the elements of the vector.

    We can probably help you better if you ask more specific questions. What exactly is it you don't understand about this program? Do you know what a Vector is? Do you know how to use for-loops?

    Have a look at The Java Tutorial for an introduction into the basic syntax and classes of Java.
    reply
      Bookmark Topic Watch Topic
    • New Topic