Help with a loop to read every 10th word

i have this loop which reads in every 10th word starting from position 1, from the vector but now i want to be able to loop though it again and get every 10th word starting from pstion2 so when i first print it out it prints out words 1, 11, 21, 31 and so on and then i loop though it again to print out words 2, 22, 32, 42 and so on and then 3, 13, 13, and so on could anyone give me any solutions please
thanks jason
Enumeration e = v.elements();
Object o;
for(int i = 0;e.hasMoreElements();i++) {
o = e.nextElement();
if (i%10 == 0){ System.out.println(o.toString()); }

Use code tags when posting code.
It's interesting that some other guy asked about a for loop like that a week ago. (http://forum.java.sun.com/thread.jsp?forum=31&thread=323439) Are you the same person with a different name? Or are you taking the same course?
As I said when I answered that question, and as should be pretty selfevident if you actually understand what the for loop you have is doing, you can select which word you print out by changing the initial value of 'i' in your loop. To print word number 2,12 etc you set 'i' to
9 at the start.

Similar Messages

  • Help with do loop

    do{     
    if((orderType != 'g') || (orderType != 'w')){     
    System.out.println("Please enter g or w only.");
    }while((orderType == 'g') || (orderType == 'w'));
    I need help with this loop... I have to make sure it will be able to pop the input back after the invalid input... i tried to fix it...wont stop and stay in same loop till it gets the valid before go to other loop... how? am i missing something?

    I know you've already been answered, but just a bit more...
    if((orderType != 'g') || (orderType != 'w'))That would always be true. All characters are either not equal to 'g' or not equal to 'w'.
    'x' : neither 'g' nor 'w'. Evaluates to true.
    'g' : not 'w', still evaluates to true.
    'w': not 'g', still evaluates to true.

  • Help with BT Vision Box - rebooting every 15-20min...

    I need help with this please!! I have been unable to watch TV using the Vision Box since last week as the box is rebooting itself at least every 15 to 20 minutes. It is impossible to record anything as the box drops out and then we cannot watch the shows. I am getting increasingly frustrated as I feel that what I am paying does not reflect the service I am getting from BT.

    Hi SineadMcB,
    Welcome and thanks for posting. I can look into this for you. Drop me an email with the details. You'll find the "contact us" form in the about me section of my profile.
    Cheers
    David
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

  • Help with while loops

    Im trying to create a while loop that outputs the revers of a string, eg nice one
    would be "eno ecin" Assuming i already have declared a variable intital string that holds the string, how do i go about this does anyone have any problem solving techniques. The charAt method needs to be used.

    i have a exam on saturday and it was a previous exam question that im trying to get help with i need to understand the course material thanks, i know how to use while loops but have trouble getting my head around this question. ill show you my code however i know its completely wrong.
    now i know i hvae to use the charAt method to return a character located at the integer i
    so i must go down after each case has been tested true therefore i want i=i-1;
    until i=0;
    String initialString="tucan";
    int i=initialString.length();
    while(i>0)
         return charAt();
         i=i-1;
         }

  • Help with Smart Card (CAC) reader installation

    Need help connecting my smart card reader to my Mac Book Pro. Either using Fire Fox, Explorer using Parallels with windows XP, or safari. I downloaded all the documentation from the Army AKO and still have problems with my Card reader.

    Hi there, I have written a really good "How-to" on firefox and CAC and also Safari. You might also want to try VMware since Parallels and DoD really don't mix at this time. If yu have any question please let me know.
    Jonathan
    http://www.applemacgeniusville.com

  • Need help with while loop format

    I'm building a form - everything works but I would like to change the way the data is output into the table.
    In other scripting languages, like PHP, you had 2 different ways of dealing with a loop:
    <?
    do while xyz
    do something here
    ?>
    - OR -
    <? do while xyz:?>
    do something here
    <?end while ?>
    I would like to do something similar to the 2nd example in .jsp but I'm not sure of the format or how to stop the loop. From the tutorial, I'm using
    <%
    while(SQLResult.next())
    UId = SQLResult.getString("uid");
    FName = SQLResult.getString("fname");
    LName = SQLResult.getString("lname");
    out.println("<tr><td>" + UId + "</td><td>" + FName + "</td><td>" + LName
    + "</td></tr>");
    %>
    Could anyone point me in the right direction? I'd prefer it if I didn't have to build the table like this if I don't have to but haven't found anything anywhere telling me otherwise.
    Thanks so much.
    Bob

    Sorry - the answer was in JSP:Java Server Pages by Barry Burd. I had just gotten the output format wrong.

  • Please Help With A Loop Using Vectors?

    I am developing a swing application and this loop has me completly stumped I have not worked with vectors alot, nut I have never seen this happen in a loop before:
    I am just going to post the loop because that is where this problem is happening.
    What I want to do is loop through CAT X amount of times and
    have an inner loop for SUBCAT X amount of times.
    fs is a formattedString class I have and eventually this text is appended to a JTextArea.
    Here is the Loop:
    Vector CAT = new Vector();
    Vector SUBCAT = new Vector();
    CAT = getCategories(Department);
    for (int i=0; i<CAT.size(); i++){
    String Category = CAT.elementAt(i).toString();
    fs.append("\nCategory: ",11);
    fs.append(Category,65);
    SUBCAT = getSubCategories(Category);
    }//End CATEGORY
    The part where I am completely stumped is, if I comment out the SUBCAT= part then the Text displays fine. If I dont it will just display the first string in the CAT Vector I have done a try and catch to see if there is an exception being thrown but there is none. The getSubCategories() method works fine b/c it is working at other parts of my program. (It Returns a Vector BTW). So commenting it out should really make no difference.
    Can anyone help me with this????
    Thanks in advance

    I will post what my output is in each scenario and maybe you can better understand what I am explaining:
    SCENARIO 1::::::::::::::::::::::::::::
    for (int i=0; i<CAT.size(); i++){
    fs.append("\nCategory: ",11);
    fs.append(CAT.elementAt(i).toString(),65);
    }//End CATEGORY
    Category: A Collars
    Category: Access Door
    Category: Aluminum
    Category: Anchors Drop In
    Category: Bits
    Category: Blades
    Category: Bolts, Nuts, Pins and Rivets
    Category: Bolts, Nuts, Pins, and Rivets
    Category: Canvas Connection
    Category: Caps
    Category: Caulking
    Category: Copper
    Category: Duct Mate
    Category: Ells
    Category: Flat Bar
    Category: Flex Duct
    Category: Galvanized
    Category: Grills
    Category: Insulation
    Category: Iron
    Category: Miscellaneous
    Category: Pipe
    Category: Reducers
    Category: Return Air Panels
    Category: Rings
    Category: Rod
    Category: Slide Gates
    Category: Spin Ins
    Category: Stainless Steel
    Category: Stick On With Damper
    Category: Tape
    Category: TDC
    Category: Tees
    Scenario 2:::::::::::::::::::::::::::::::::
    Category: A Collars
    for (int i=0; i<CAT.size(); i++){
    fs.append("\nCategory: ",11);
    fs.append(CAT.elementAt(i).toString(),65);
    SUBCAT = getSubCategories(CAT.elementAt(i).toString());
    }//End CATEGORY
    Now do you see:
    The SUBCAT = getSubCategories(CAT.elementAt(i).toString()); should not be affecting the loop. It should just be assigning a new Vector to SUBCAT. I know that it is missing the inner loop in this example, but this is how I found out the loops where not working right.

  • Help with Video Loop

    Hi
    I've been at this for over 24 hours. I have a small video
    clip which is embedded in DW and uploaded...
    http://www.forpetsake.ca/about2.html
    Originally I purchased this ,mov from istockphoto.com and
    used QT pro to convert into a .flv. Once converted I brought it
    onto the Flash stage. In published settings I selected the 'loop'
    option and then exported out to a .swf. Once I embedded this .swf
    into my DW page, I uploaded all to my server including the .html
    created with the .swf, in fact I uploaded the .flv/.swf/.html into
    a seperate folder on my server.
    All I want to do is set this movie to loop, maybe pause for a
    couple seconds before each loop.
    I'm a simple person who only understands simple explanations.
    Can someone please walk me through the steps in Flash CS3 to
    get this short clip to loop.
    ps" The Property Panel selectors (loop-autoplay) make no
    changes whatsoever in DW CS3 with respect to this video.
    Thanks in advance for any help you can provide.

    If you're importing the FLV file into a SWF file (which is
    not recommended these days), then just add a gotoAndPlay(1) action
    to a keyframe you add at the very end of your Flash timeline.
    If, however, you use the FLVPlayback component, you can write
    ActionScript to listen for the "complete" event and tell the video
    to restart when that event is detected.
    Also, use SWFObject (
    http://blog.deconcept.com/swfobject)
    to embed a SWF into your HTML document. Dreamweaver and Flash's
    detection scripts aren't as good. (my two cents)
    HTH.

  • Need help with the loop

    I'm a beginner. I'm trying to get this output
    Initial number of stars:
    7
    Here's my program. What's wrong with it? Please help
    import java.io.*;
    class starWedge
    public static void main (String[] args ) throws IOException
    int numStars; // the number of stars
    int row ; // current row number
    int star; // the number of stars in this row so far
    BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
    String inputData;
    // collect input data from user
    System.out.println( "Initial number of stars:" );
    inputData = userin.readLine();
    numStars = Integer.parseInt( inputData );
    row = 1;
    while ( row <= numStars )
    star = 1;
    star = numStars - star;
    System.out.print("*");
    star = star + 1;
    System.out.println(); // end each line
    row = row + 1;

    Okay the one thing that I see immediately is that your while loop never actully exits. Not once. Why? Well simple your exit condition is the row <= numStars, yet nither numStars nor row actually change their values within the loop. In short row always equals 1 and thus never is equal to greater than numStars and the while loop does not terminate.
    Second thing is that your star drawing logic is not correct. Meaning you have not told to draw the specific number of stars in one given line. For starters the System.out.println() command should be in the loop not outside it. For your purposes a for-loop nested within a while-loop is much better.
    If you think you know what's wrong your program than read no further and go try it on your own. But if you still have no clue below is my modification of your code that actually produces the pattern you want, it might provide you with more hints.
    import java.io.*;
    class starWedge{
    public static void main (String[] args ) throws IOException{
         int numStars; // the number of stars
         int row ; // current row number
         int star; // the number of stars in this row so far
         BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
         String inputData;
         // collect input data from user
         System.out.println( "Initial number of stars:" );
         inputData = userin.readLine();
         numStars = Integer.parseInt( inputData );
         row = 1;
         while (numStars > 0){
         for(star = 1; star<=numStars; star++){
              System.out.print("*");
         numStars = numStars - 1;
         System.out.println(); // end each line
    }

  • Help with uninstalling "old" Adobe Reader

    Since I trust anything Adobe 100%, I did not hesitate to follow a link (contained in "Adobe for Andoid" email from you to me) to install Adobe Reader on my new NOOK HD+ 32.  IT IS A "BAD" LINK, details were forwarded to Adobe by Chrome Support 7-2-13.  What I have been told from Barnes and Noble, Chrome, Google and Adobe "HELP" Professionals  is to uninstall the download.
    You'd think even a 56 year old tech-novice could handle this, right?!?  I Can't because the "Unfortunately System UI message freezes everything up until I respond "okay".... Between my "okay" and typing the "uninstall "  address to my Search bar, the "UI' message has taken over my screen and has frozen every  click I know how to make.  After doing this 5+times, all of the icons begin to shake and then the page completely turns itself off.
    I am hoping someone is able to advise me how to "uninstall" from somehere other than my Nook.
    Thank you very much,
    Mizrallen623

    It's really hard to say what's going on without knowing more about the system. It's possible that the program is generating an FDF (Forms Data Format) file and launches it, causing the PDF to load and populate with the data in the FDF. Folks have reported that recent changes to Reader have broken this type of thing. So you may need to go back to an even earlier version, such as 9.2 or 9.3, or somehow contact the developers of the application for help.
    Is this something that happens in a web browser?

  • Need help with while loops

    Hello let me first explain what im trying to achive:
    I want a moving square that you control with the arrow keys on the keyboard. It has to be smooth ie able to move fast without looking like its jumping and it has to be able to move diagonaly aswell. Think of that arcade game Raiden ...you know the birds-eye view plane flying game...another thing! I'd prefer if it didnt use timers - i made one already using 4 timers and it works great but 4 timers is a little extreme - SO NO TIMERS !
    I was thinking while loops, but i cant seem to get it working. I dont want to put in all the code so ill just say that I have 4 booleans: up, down, left right and the following code:
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_UP) {
    up = true;
    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
    down = true;
    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
    left = true;
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
    right = true;
    repaint();
    For the KeyReleased part i have the same as above exept it sets the booleans to false.
    Soooo in theory if i set up a while loop like this (using the up direction as an example) :
    while (up == true) {
    [move square up]
    So therefore when i press and hold the up arrow the loop will keep going untill i realease it right? WRONG ! it just keeps repeating indefinatly and it doesnt even do the " [move square up] " bit. I put a System.out.print in the loop to test and it kept printing out the message but it still didnt do the actual " [move square up] " bit.
    Im not sure if im putting the while loop in the right place either....If anyone has any idea on how to use while loops in this way please heeeelp ! Its so annoying because it just doesnt work ive tried so many ways...
    any help would be greatly apreciated !!!!

    Maybe you want something like this? You have to pause during the loop to allow for other events to happen, like if y ou release a key or whatever.
    while( true )
       if( up ) moveUp();
       else if( down ) moveDown();
       if( left ) moveLeft();
       else if( right ) moveRight();
       try
          Thread.currentThread().sleep(10);
       catch( InterruptedException e )
          System.out.println( "Thread interrupted!");
    }

  • Need help with while loop and shift registers

    I have a large data set and need to read in the data at maybe 200 samples at a time, process these samples through my VI, and have it append and concatenate a separate lvm file.  The part where I am confused is the shift registers. How do I limit the number of samples read in an iteration? How do I get the while loop to stop when all the data are read in?
    I've attached my diagram, maybe there is something wrong with my technique?
    Solved!
    Go to Solution.
    Attachments:
    shiftreg.JPG ‏56 KB

    This will give you an idea.  There are plenty of other (probably more efficient) methods.  This is a basic, quick and dirty solution to help you grasp the overall concept.
    Using LabVIEW: 7.1.1, 8.5.1 & 2013
    Attachments:
    ShiftRegLoop.JPG ‏54 KB

  • I need some help with a loop..

    Hi,
    I am creating a program to calculate time, when entering the time and how many minutes you want to add. The program is done, except for the fact that I need to build a loop to add 1 to h (for hours) for every 60 minutes. My idea was to have the 'if-else' statement in newHours() loop. I tried to enclose this inside a 'do-while' loop, with while(newMin>60), but it seems that it creates an infinite loop as the program just sits there. If someone could check my code and gimme some advice I would reall appreciate it.
    Time.java
    import javax.swing.*;
    public class Time
         private String addMin;
         private String hours;
         private String minutes;
         public Time()
         public Time(String inHours, String inMinutes)
              hours = inHours;
              minutes = inMinutes;
         public void setTime(String inHours, String inMinutes, String addMinutes)
              setAddMin(addMinutes);
              setHours(inHours);
              setMinutes(inMinutes);
         public String getTime()
              return toString();
         public void setAddMin(String addMinutes)
              addMin = addMinutes;
         public String getAddMin()
              return addMin;
         public void setHours(String inHours)
              hours = inHours;
         public String getHours()
              return hours;
         public void setMinutes(String inMinutes)
              minutes = inMinutes;
         public String getMinutes()
              return minutes;
         public String newMinutes()
              int m, m2, newMin;
              m = Integer.parseInt(minutes);
              m2 = Integer.parseInt(addMin);
              newMin = m + m2;
              while(newMin>59)
                   newMin = newMin - 60;
              if(newMin>9)
                   return Integer.toString(newMin);
              else
                   return "0" + Integer.toString(newMin);
         public String newHours()
              int m, m2, h, newMin, temp;
              m = Integer.parseInt(minutes);
              m2 = Integer.parseInt(addMin);
              h = Integer.parseInt(hours);
              newMin = m + m2;
              if(newMin>59)
                   temp = newMin - 60;
                   h = h+1;
              else
                   h = h;
              return Integer.toString(h);
         public String convert()
              int h, h2;
              String day;
              h = Integer.parseInt(newHours());
              if(h>=12)
                   day = "PM";
                   h2 = h - 12;
                   hours = Integer.toString(h2);
              else if (h == 12)
              hours = Integer.toString(h);
              day = "PM";
              else
                   day = "AM";
                   hours = Integer.toString(h);
              return "your converted time is\n" + hours + ":" + newMinutes() + day;
         public void display()
              JOptionPane.showMessageDialog(null, this.convert());
    timeDriver.java
    import java.util.*;
    import javax.swing.*;
    public class timeDriver
         public static void main(String[] args)
              String input, hour, minute, addMin;
              int h, m;
              input = JOptionPane.showInputDialog("Enter time in 24-hour notation:");
              hour = input.substring(0,2);
              minute = input.substring(3, 5);
              addMin = JOptionPane.showInputDialog("How many minutes to add?");
              Time A = new Time();
              A.setTime(hour, minute, addMin);
              A.display();
    }

    Why do you think you need a loop at all?
    When you post code, wrap it in [code][/code] tags so it's easier to read.
    You realize that what you're writing basically duplicates the java.util.Calendar class (and its subclass GregorianCalendar), right?

  • Help with Flash Banner Opening on every page

    Hey guys I been trying to optimize my site abit. I seen on
    some new flash templates that when the flash banner opens the first
    time the browser will not call it again when clicking on new page
    links. I also seen the banner incorperated with an iframe so it
    only calls it once.
    Currently I have 6 .html pages each calling the flash banner
    every time their clicked. This is taking loading time whenever a
    user browses to a different page.
    my site is
    http://xpservers.net
    and another i created is
    http://energreenmetering.com
    Can someone help me out ?

    A 5.6MB file is way too big for a Flash movie to stream easily, even over DSL. Even 1 MB is pretty big for a Flash movie. A loading status indicator requires programming using the Flash authoring application.
    The Flash export from keynote is probably not compressing the images a lot. Also the size of the presentation (800x600) is pretty large, and this is giving you a big file.
    Try searching versiontracker.com for other slideshow tools with Flash export that will allow you to create a smaller canvas and compress your images more. But be aware that a series of bitmaps will always create a large Flash movie.
    Good luck!

  • Weird Problem- Help With Logic Loops

    Hi all,
    I've been using Logic Express 8 for about 2 years and I've got a pretty good handle on things. However I keep having this small little problem and usually restarting the software fixes it, but not this time.
    My problem is this: I'm trying to make some beats using software instruments. So I click on "Drums and Percussion" then "Ultrabeat" then choose my drum kit. I start punching in my beats but Logic is playing some Apple Loop on top of it! Theres no notes on the track and yet it still plays this random beat! I can adjust the tempo and the beat adjusts to it.
    The problem is there is nothing there. Its a blank track, but this beat keeps playing.
    I used to just restart the program when it happened and it usually took care of it, however it won't fix it this time.
    I know it's probably some check box I don't have clicked or something but if someone could help me out, I'd be very appreciative.
    Thanks,
    Josh

    Ah yes!
    Thank you JG99!!!
    I forgot to go into the Ultrabeat menu, and turn off the "example beat" that they give you. I knew it was some checkbox that I didn't unclick or click.
    Thank you sir, you are a gentleman and a scholar.

Maybe you are looking for