• Post Reply Bookmark Topic Watch Topic
  • New Topic

can anybody explain the program?  RSS feed

 
satya narayan reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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());
}
}
}
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • 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.
     
    Jesper de Jong
    Java Cowboy
    Sheriff
    Posts: 16028
    87
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!