Need help with java File IO ( Removing the first line from a file )

Hi guys ,
I am currently doing a project in which I need to extract out the values from the second line of a file to the end. The question is how do I ignore the first line ??
I thought of two possible answers myself. One is to use randomaccessfile to read and rewrite. But the file may be HUGE so storing the whole file in memory is not a very good idea.
Second is to jump to second line before doing while ((str = in.readLine()) != EOL) ... or just delete the first line from the file. Can anyone suggest a better solution or show me some sample codes ? Thanks.
regards
billyam

Just skip the first line (bufferedReader.readLine()), add a comment, and then handle the rest of your file

Similar Messages

  • Need help with how to store data in array in from reading file

    i have a file named xxx.txt
    i need to retreive data from that file. the data that i want to retrieve is enclosed with << >>
    temp xxx-123 ccc << 90.5>>
    haha xxx-563 sss 85.2
    after a few lines, the another record appear.
    temp2 xxx-123 ccc << 190.5>>
    haha2 xxx-563 sss 885.2
    i would like to record down the data, 90.5 & 190.5, how do i go about doing so, will appreciated it if someone would guide me along. thanks

    After you have read a line from the file either
    find the location of << and >> and substring the stuff in between or
    use regex (regular expression) however this is advanced and may be beyond your level of understanding.

  • I need help writing a script that finds the first instance of a paragraph style and then changes it

    I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style.  I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style.  Any help would be greatly appreciated, thanks!

    Hi,
    Do you mean first instance of the paragraph style
    - in a chosen story;
    - on some chosen page in every text frames, looking from its top to the bottom;
    - in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
    If story...
    You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
    Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
    so:
    Story.findText()[0].appliedParagraphStyle = Style_1;
    //==> this will change a paraStyle of 1st occurence of story to "Style_1".
    If other cases...
    You would need to be more accurate.
    rgds

  • How to remove the first number from a queue?

    Hi,
    I am trying to implement the following code for a queue. I've made an attempt on the RemoveFromQueue method, but it doesn't seem to work. How would i correctly be able the method for it to be able to remove the first number from the queue? thanks.
      if (q.QueueIsEmpty())
            System.out.println("Queue empty");
      else
             int firstEntry = q.RemoveFromQueue();     
                  System.out.println("Integer extracted  : "  + firstEntry);
    int RemoveFromQueue ()
             if (QueueIsEmpty())
                   return false;
             else
                  for(i=1; i <= total; i++)
                        Queue[i-1] = Queue;
                         total--;
                         return -1;
    }

    int RemoveFromQueue ()
    if (QueueIsEmpty())
    return false;
         else
         for(i=1; i <= total; i++)
         Queue[i-1] = Queue;
         total--;
         return -1;
    }Here we go:
    1) if the queue is empty you attempt to return 'false' while the method itself is
    supposed to return an int.
    2) you attempt to assign an entire queue to a single queue element.
    3) your indentation is a mess.
    4) why do you test for an empty queue outside of that method?
    5) use pencil and paper and scribble down exactly what you want to do.
    6) don't use initial uppercase letters for method names.
    kind regards,
    Jos

  • The first line in a file is supressed

    hi all,
    i have a really weird problem.
    i have a file with a lot of data and i am using a file adapter with file content conversion to parse it.
    the file adapter is a sender one.
    the problem come when i do read the file and then it ignore the first line of the file.
    all the lines from the second one forward is shown in SXMB_MONI but the first line of the file isn't.
    i can't seem to figure out what the problem is, i tryed looking for some kind of attribute in the file adpater but had no luck.
    could you please help me?
    btw,
    the file structure is: header,1,body1,<wildcard>,body2,<wildcard>
    Edited by: Roi Grossfeld on Oct 29, 2008 4:24 PM

    Recordset Structure: H1,1,B1,<wildcard>,B2,<wildcard>
    Key Field Name: RecordType
    H1.fieldFixedLengths 6,2,8,1,1,3,30,5
    H1.fieldNames FileNo,RecordType,TransmissionDate,Car_Truck,BU,MD,FileName,Count
    H1.keyFieldValue H1
    B1.fieldFixedLengths 6,2,10,27,8,8,4,5,3,11,9,9,11,11,9,9,7,9,11
    B1.fieldNames FileNo,RecordType,InvoiceNumber,VesselName,MMSEShipmentDate,PlanArrivalDate,DeliveryPlace,Units,Currency,ModelPriceAmount,OptionPriceAmount,ColourPriceAmount,REPriceAmount,TotalPriceAmount,FreightChargeAmount,InsuranceFeeAmount,MiscellaneousAmount,VATAmount,GrandTotalAmount
    B1.keyFieldValue B1
    B2.fieldFixedLengths 6,2,10,12,12,12,5,6,12,3,3,3,4,17,7,7,12,8,5,3,9,7,7,9,9,7,9,4,20
    B2.fieldNames FileNo,RecordType,InvoiceNumber,MDOrderNumber,MMSEOrderNumber,MMSECaseNumber,ModelYear,BodyType,Model,ExteriorColourCode,InteriorTrimColourCode,OptionCode,RearEquipment,VehicleIdentificationNumber,ChassisModel,CSequenceNumber,EngineModel,ESequenceNumber,KeyNumber,Currency,UnitModelPrice,UnitOptionPrice,UnitColourPrice,UnitRearEquipmentPrice,UnitTotalPrice,UnitVATAmount,UnitTotalVAT,VATRate,VATNumber
    B2.keyFieldValue B2
    ignoreRecordsetName true
    Edited by: Roi Grossfeld on Oct 29, 2008 4:39 PM

  • Read to get the last line from a File

    Hi
    I am sending in a clarification , hoping that I get an efficient solution from the group, should somebody have come across this scenario and implemented.
    How to read or get the last line from a text file , which usually have a no of records, without actually reading or looping through all the lines
    I know there is some solution with the RandomAccessFile, but given there can be some encoding issues or so.
    Please let me know if somebody have implemented the same.
    Thanks n advance

    The character encoding could, indeed, be an issue especially with UTF-8. I think what I'd do is to create a byte array with the encoded, expected end of line sequence in it and work on the file in bytes. For example, seek to the last 100 bytes of the file, read those bytes and look for an EOL sequence backwards. If not found read the previous 100, 200, 400 bytes etc. until you do find an end of line. Then seek to after the EOL and read normally. Remember an EOL sequence might cross a boundary.
    UTF-8 would be a problem, especially with a unix format file because you might mistake part of a multi-byte sequence for '\n'. To be reliable on UTF-8 you'd need to go back three characters looking for sequence start markers (has the previous character got the top bit set, or the one before that the first two bits set, or the one before that the top three bits). Or you could just react to an encoding exception and try another position.

  • MQSeries---to remove the first message from queue

    Hi all,
    I have some question in MQSeries in Sun Solaris.
    I would like to ask if there are any command in runmqsc that can remove the first message only? I know the command 'CLEAR QLOCAL' but it removes all the messages inside the queue but not only the first one.
    Thanks a lot.
    Jane.

    You might have more luck with pure MQSeries questions on www.mqseries.net

  • Need help with Java app for user input 5 numbers, remove dups, etc.

    I'm new to Java (only a few weeks under my belt) and struggling with an application. The project is to write an app that inputs 5 numbers between 10 and 100, not allowing duplicates, and displaying each correct number entered, using the smallest possible array to solve the problem. Output example:
    Please enter a number: 45
    Number stored.
    45
    Please enter a number: 54
    Number stored.
    45 54
    Please enter a number: 33
    Number stored.
    45 54 33
    etc.
    I've been working on this project for days, re-read the book chapter multiple times (unfortunately, the book doesn't have this type of problem as an example to steer you in the relatively general direction) and am proud that I've gotten this far. My problems are 1) I can only get one item number to input rather than a running list of the 5 values, 2) I can't figure out how to check for duplicate numbers. Any help is appreciated.
    My code is as follows:
    import java.util.Scanner; // program uses class Scanner
    public class Array
         public static void main( String args[] )
          // create Scanner to obtain input from command window
              Scanner input = new Scanner( System.in);
          // declare variables
             int array[] = new int[ 5 ]; // declare array named array
             int inputNumbers = 0; // numbers entered
          while( inputNumbers < array.length )
              // prompt for user to input a number
                System.out.print( "Please enter a number: " );
                      int numberInput = input.nextInt();
              // validate the input
                 if (numberInput >=10 && numberInput <=100)
                       System.out.println("Number stored.");
                     else
                       System.out.println("Invalid number.  Please enter a number within range.");
              // checks to see if this number already exists
                    boolean number = false;
              // display array values
              for ( int counter = 0; counter < array.length; counter++ )
                 array[ counter ] = numberInput;
              // display array values
                 System.out.printf( "%d\n", array[ inputNumbers ] );
                   // increment number of entered numbers
                inputNumbers++;
    } // end close Array

    Yikes, there is a much better way to go about this that is probably within what you have already learned, but since you are a student and this is how you started, let's just concentrate on fixing what you got.
    First, as already noted by another poster, your formatting is really bad. Formatting is really important because it makes the code much more readable for you and anyone who comes along to help you or use your code. And I second that posters comment that brackets should always be used, especially for beginner programmers. Unfortunately beginner programmers often get stuck thinking that less lines of code equals better program, this is not true; even though better programmers often use far less lines of code.
                             // validate the input
       if (numberInput >=10 && numberInput <=100)
              System.out.println("Number stored.");
      else
                   System.out.println("Invalid number.  Please enter a number within range."); Note the above as you have it.
                         // validate the input
                         if (numberInput >=10 && numberInput <=100)
                              System.out.println("Number stored.");
                         else
                              System.out.println("Invalid number.  Please enter a number within range."); Note how much more readable just correct indentation makes.
                         // validate the input
                         if (numberInput >=10 && numberInput <=100) {
                              System.out.println("Number stored.");
                         else {
                              System.out.println("Invalid number.  Please enter a number within range.");
                         } Note how it should be coded for a beginner coder.
    Now that it is readable, exam your code and think about what you are doing here. Do you really want to print "Number Stored" before you checked to ensure it is not a dupe? That could lead to some really confused and frustrated users, and since the main user of your program will be your teacher, that could be unhealthy for your GPA.
    Since I am not here to do your homework for you, I will just give you some advice, you only need one if statement to do this correctly, you must drop the else and fix the if. I tell you this, because as a former educator i know the first thing running through beginners minds in this situation is to just make the if statement empty, but this is a big no no and even if you do trick it into working your teacher will not be fooled nor impressed and again your GPA will suffer.
    As for the rest, you do need a for loop inside your while loop, but not where or how you have it. Inside the while loop the for loop should be used for checking for dupes, not for overwriting every entry in the array as you currently have it set up to do. And certainly not for printing every element of the array each time a new element is added as your comments lead me to suspect you were trying to do, that would get real annoying really fast again resulting in abuse of your GPA. Printing the array should be in its own for loop after the while loop, or even better in its own method.
    As for how to check for dupes, well, you obviously at least somewhat understand loops and if statements, thus you have all the tools needed, so where is the problem?
    JSG

  • Need help with java file scanner and objects

    Hi, i've got an assignment that asks me to do these, but i cant seem to get around in solving it. Any help will be much appreciated. TYVM!
    Create a class called TVProgram that can store some important details of a television program:
    - name of the show
    - the channel the show is on
    - the start time (in 24-hour format)
    - the end time (in 24-hour format)
    Write a program that uses this class.
    Your program will read a list of TV programs, making up a schedule for an evening's TV: for you convenience, you will be able to download a sample file listing. The listing will consist of one line for each of the above fields, in the above order, for each program, followed by a line containing only the "#" character. For example, here is the start of such a file.
    At the Movies
    ABC
    1800
    1830
    The Einstein Factor
    ABC
    1830
    1900
    Your program should start with a little menu to prompt whether to read from standard input or a file:
    Please choose a number for the way you will input the TV schedule:
    1. Read from standard input
    2. Input from a file
    Your program should first read the complete schedule, then loop through all the programs in the schedule and prompt the user as to whether they want to record the program or not. For example, the program should print:
    At the Movies is showing on ABC from 1800 to 18.30.
    Do you want to record it: type Y or N.
    If the user types Y then the program sets this T Vprogram to be recorded. If the user types N, the program goes to the next entry and prompts the user again. If the user types something other than a Y or N (or y or n), then the program should prompt for a proper answer:
    Do you want to record it: type Y or N.
    Once the complete schedule has been shown to the user, the program loops through those that the user has said they want to record and checks for any clashes---i.e. any times at which the user wants to record two programs at the same time. For any clashes, your program should show these to the user and insist that only one be selected for being recorded. For example:
    At 1830 you want to record both 1. The Einstein Factor on ABC and 2. The Biggest Loser on Ten.
    Please pick option 1 or 2 to record.
    Again, if the user selects an option other than 1 or 2 in the above, then the program should make the user to make another selection until they type a legal value.
    If the schedule is in time-start order (see "Assumptions" below), then a simple way to check for clashes is:
    - as you loop through the schedule of shows, keep track of the latest end-time the user wants to record;
    - if any program the user says they want to record has a start-time before this latest end-time, then this is a clash.
    There are different ways to keep track of clashes: you can keep an array (a list of clashes) of arrays (each of these is the list of clashing programs); you could create a Clash class.
    Finally, after going through all clashes, print out the list of programs that the user still wants recorded.
    Here is the list of programs that will be recorded for you:
    From 1830 to 1930, The Biggest Loser, on Ten.
    From 1930 to 2030, Who Do You Think You Are, on SBS
    -----

    * @(#)TVProgram.java
    * @author      Okky Satya
    * @version 1.00 2008/3/29
    import java.util.*;
    import java.io.*;
    public class TVProgram {
         private String name;
         private String chnl;
         private int strt;
         private int ends;
         public TVProgram(String showName, String channel, int start, int end ){
              this.name = showName;
              this.chnl = channel;
              this.strt = start;
              this.ends = end;
        public static void readFileInput() {
        List prog = new ArrayList();
        Scanner inputFile = null;
         try
        inputFile = new Scanner(new File("tv_schedule"));
         catch (FileNotFoundException fe)
        System.out.println("File not found!");
        System.exit(0);
        while(inputFile.hasNext()== true){
             while (inputFile.nextLine()!="##")
                  new TVProgram;
        public static void readInput(){
        public static void loopInput(){
        public static void showList(){
        public static void checkUserList(){
        public static void main(String[] args){
             int menuChoice = 0;
             System.out.println("Please choose a number for the way you will input the TV schedule:\n  1. Read from standard input\n  2. Input from a file");
             switch(menuChoice){
                  case 1:
                       readInput();
                       break;
                  case 2:
                       readFileInput();
                       break;
             loopInput();
             checkUserList();
             showList();
    }

  • Need help with Apps misbehaving and upgrading the MacOS: The all-in-one post. ;)

    Hi there,
    So, I've been browsing the SL and Mavericks forums for the last days but although I have fetched some useful tips and answers, still need some help. Let me put it diary-style so I can be more concise ;)
    Here's my current system profile:
    iMac 27" (aluminium back- if I'm no wrong, from around late 2009-mid 2010)
    MacOS 10.6.1 Never updated.
    3.06 Ghz Intel Core2 Duo
    4Gb RAM
    LaCie Big Disk via FireWire 800
    Internet access via Ethernet port (cable)
    And here's The Issues Log:
    – Day one: First ever Kernel Panic. Restart. Nothing (apparently) wrong.
    – 3 weeks elapsed: Second Kernel Panic. Same. iMac restarts fine. Apps fine. No missing files. No misbehaviour experiences.
    – After a month or so: One morning, Skype decides on its own to stop launching. The night before, I chatted with one of my clients, fine as always, but at the next day, nothing. Computer is usually shut off for the night. And so it was that night. Updated Skype and also did all the guest account trick / repaired permissions / repair ACLs. Nothing worked. Overwrote the Skype app with a former functioning version I have in an MacOS 10.5 system. Didn't work. Now I have to chat on the MacOS 10.5 computer. No good.
    – 15 days ago or so: After realising that I no longer have my HP1515n printer (it ran out of inks and thrashed it. It costs more to refill than to buy a new one), I deleted the printer from the printers list in the System Prefs Pane.
    – Last week: Acrobat (CS4) won't launch a PDF file and freezes. Spinning beach ball. Force quit and try opening the PDF file again. Freezes again. And again. And again. With that file and every other PDF.
    Photoshop CS5 fails to open or crashes when attempting to open any jpg or tiff file. InDesign and Illustrator CS5 are frozen and had to force quit both. MacOS 10.5
    Restart the iMac thinking it is just a "common" bad day and hoping everything will be alright after the restart, but nope.
    Not only the CS5 stops working; MSOffice stops working too. Spinning beach ball. Begin to suspect of the deletion of the printer, however, I also deleted the same printer in the above mentioned 10.5 system and I'm not experiencing anything strange. Reinstalled the HP drivers but nothing remarkable happens.
    Then, try to uninstall CS5, CS4, Office, etc. Try to reinstall Acrobat CS4 and the CS5 apps. Reinstall Office. Nothing. Just Outlook works.
    Since I had to desperately meet deadlines, convinced a colleague to come over to the studio and -I know, I know- allowed me to install a copy of CS6. It seems to work fine, except for Acrobat, which randomly freezes/hangs/works and Photoshop, which works fine unless you want to open a layered file containing text layers or if you want to type text on a normal file, because it freezes as soon as the Text Tool is pressed in the toolbar, of course, spinning beach ball again.
    Well, Illustrator CS6 sometimes shows a strange black thin frame overlaid on the interface but goes away by switching to another workspace and then back to the current. InDesign CS6 seems to be fine and making PDFs as expected. However, as I said before, it is pure luck if Acrobat accepts to open the file or even if it launches. Spinning beach ball when freezing/hanging.  
    As a method for eliminating possible culprits, did a clean up of the Suitcase Fusion database, removed duplicate and a few (less than 10) corrupted fonts.
    Removed completely MSOffice reinstalled and updated. Nothing. Now I neither have MSoffice running.
    I am no rookie but I can't even imagine what can cause such amount of misbehaviour, (kernel panics have something to do? malware? lack of system updates? MacHD is damaged?) so I'm thinking of a few scenarios:
    Backing up my projects and user folder –anything else to backup? (In fact I've already done that)– and:
    1. Do a clean install. Not sure if it will be best to completely erase the whole drive or if a standard reinstallation will be enough.
    2. Take the machine to a Genius Bar to see if there's anything that can be done without major OS messes.
    3. Erase the drive and go through the Mavericks upgrading (SL to Ln to MLn to Mavcks), although not sure if this upgrade is worth yet.
    4. Replace HD for a brand new one and either step 1 or 3.
    5. As a complement, I'm thinking of adding more RAM.
    Well. It is really the first time I don't know what to do. I have work to do and would not want to face a week away from my main computer and since most of the files are CS5-6 and hence, can't move to my wife's iMac...
    Apologies if this post feels too long, but I will truly appreciate any kind of input and advice on one of more of the issues mentioned in this post.
    And if it fits best in any other forum, please also let me know.
    Cheers and thanks in advantage.

    You have to use the Base Station Menu on the Menu Bar at the very top of your screen.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Need help with Java Programming

    Hello All,
    I dont know how to save all the lines separatly and then work with the numbers?
    Example TxtIn:
    2 5
    0 9 2 3 4 // I dont know how many lines will appear, and dont know how many numbers in a line
    1 2 3 9
    1 5 4
    2 0 0 5 6
    2 5 1 9
    4 6 1 5
    4 9 1 8
    9 1 4 8
    9 5 0
    Example TxtOut:
    1 9 4 0
    I would really appreciate your help in this.
    In my code, i only past one time in the text file, and clear the numbers of the list, but i need to make more check =S
    Here is the code:
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.StringTokenizer;
    * @author Antonio
    public class web {
        /** Creates a new instance of Main */
         * @param args the command line arguments
        public static void main(String[] args) throws FileNotFoundException {
            int contador;
            ArrayList<Integer> lista = new ArrayList<Integer>();
            Scanner scn = new Scanner(new File("in.txt"));
            try {
            PrintWriter fileOut = new PrintWriter(new FileWriter("out.txt"));
            int ciudades = scn.nextInt();
            int aerolineas = scn.nextInt();
            int ciudadabuscar = scn.nextInt();
            int aerolinea = scn.nextInt();
            int bandera=0;
            while (scn.hasNextLine()){
                    String cad = scn.nextLine();
                    StringTokenizer st = new StringTokenizer(cad," ");
             while (st.hasMoreTokens())
                    String t = st.nextToken();
                    lista.add ( Integer.parseInt(t) );
               int a[]= new int[lista.size()];
               for (int x=0; x<lista.size(); x++)
                            a[x] = lista.get(x);
                          for (int x=0; x<lista.size(); x++)
                   for (x=1;x<lista.size();x++){
                            if (ciudadabuscar == a[0] && aerolinea == a[1])//tenia x=1
                                for (x=2;x<lista.size();x++)
                                { fileOut.printf("%d ",a[x]);
                                  ciudadabuscar= a[2];
                                  bandera = 1;}
                         lista.clear();
            if(bandera==0){
            fileOut.println("No hay destinos posibles por esta línea");
            fileOut.close();
            }catch(FileNotFoundException ex){}catch(IOException ex){}
    }

    #1 Solution is the same as i am working but...if i found AND another pair needs tobe searched...i dont know how to start again with step 1...
    i onli continues reading..that is why i am never show
    2 5//i am reading the file looking for 2 and 5
    0 9 2 3 4
    1 2 3 9
    1 5 4 // I NEVER show the number 4....
    2 0 0 5 6
    2 5 1 9 // here i found them...and now i have to look in the file 1 5 and 9 5 (but 1 5 are before this..so i can never found them)
    4 6 1 5
    4 9 1 8
    9 1 4 8
    9 5 0 // here i found 9 5
    Correct OutTxt: 1 9 4 0
    My OutTxt: 1 9 0...Never show the number 4, because i dont know how to start again...
    thank u
    Edited by: Ing_Balderas on Dec 11, 2009 2:25 PM

  • Need help with java J2Se 5.0 upgrade 2

    Having problems with Java when playing on Pogo, the Vaults of Atlantis. When loading, I am getting a message that says that I need to remove and download again, java. That it is not working correctly. I did that yesterday, 05/27/05 and am still experiencing the problem but only after signing off from Pogo and AOL and then trying to sign back on again later in the day. I have to shutdown my computer and bring it back up again and then I can load the Vaults of Atlantis. I have noticed that when I do sign-off from Pogo and AOL, that my java cup stays on in my deskbar. Is that supposed to be normal or is it supposed to disappear? If it is supposed to disappear, what can I do to fix that problem?
    Please, can anyone help?

    Go here http://www.java.com/en/ and click "Download Now".
    If that has problems, click the "Manual Download" link and download the "Windows (Offline Installation)".
    If there are problems, review the Help information to resolve.

  • Need help with Java programming installation question

    Sorry for my lack of knowledge about Java programming, but:....
    A while back I thought I had updated my Java Runtime Environment programming. But I now apparently have two programs installed, perhaps through my not handling the installation properly. Those are:
    J2SE Runtime Environment 5.0 update 5.0 (a 118MB file)
    and:
    Java 2 Runtime Environment, SE v 1.4.2_05 (a 108MB file)
    Do I need both of these installed? If not, which should I uninstall?
    Or, should I just leave it alone, and not worry about it?
    Yeah, I don't have much in the way of technical knowledge...
    Any help or advice would be appreciated. Thank you.
    Bob VanHorst

    Thanks for the feedback. I think I'll do just that. Once in a while I have a problem with Java not bringing up a webcam shot, but when that happens, it seems to be more website based than a general condition.

  • Need help with java

    ok so i have a midterm and need help this question that is gonna be on the midterm. i dont know how to do it and its worth 16 marks!!!! here it is
    the UW Orchestra wants to produce a CD containing all the pieces of music
    from its upcoming concert. In order to do that, it needs to calculate the total length of time for the
    CD. In addition, the conductor wishes to know which piece of music has the longest duration.
    Sample output for the program.
    The Swan (3.88)
    The Bee (0.98)
    Claire de Lune (6.02)
    Liebesfreund (3.38)
    Ragtime (3.48)
    The total time for the CD is 18.74 minutes.
    The longest piece is Claire de Lune.
    Do not include the HTML that is required to embed the program into a Web page (that is, show
    only what you would write between <script> and </script> tags).
    [4 marks] In the following space, define a function, Print, that takes two parameters, Title and
    Length, and outputs a line of text such that Title appears in italics, followed by Length in
    parentheses. The function also returns the value of Length.
    For example, Print("My World",30) will output the line
    My World (30)
    and return the value 30.
    Put your JavaScript program for the remainder of this question in the space provided on the next
    two pages.
    [9 marks]. For each piece of music, your program should input the title of the piece and the
    duration (in minutes) for that piece, and it should output a line showing those values using the
    Print function just defined. After all pieces have been listed, the program should output the
    total length of time for the CD, adding in 0.25 minutes between each piece of music (which is
    needed on the CD to separate the pieces).
    [3 marks] The program should also output the name of the piece that has the longest playing
    time.
    Use reasonable variable names, indentation and good programming style. Documentation and
    comments are not required, but you may add them to explain any assumptions you might want to
    make. You need not check that the input is valid, and you may assume that no two pieces have the
    same duration.
    can anyone help me out! i would be indebt of ur kindness if u can help me out!

    This forum is for Java, not JavaScript. The two have nothing to do with each other.
    And anyway, this is your studying, so you should try to do it, put forth your best effort, and ask specific questions (on the proper fourm).

  • Need Help With Java Query String

    I'm new to Java and I'm passing data via a URL to another page(I'm not using a form). I have been succesfull in decoding the string to return the name value below:
    <SCRIPT LANGUAGE="JavaScript">
    function decodeSearchString() {
    var nameValue = new Array();
    var searchStr = unescape(location.search.substring(1));
    if (searchStr) {
    var formElement = searchStr.split("&");
    var tmpArray = new Array();
    for (k = 0; k < formElement.length; k++) {
    tmpArray = formElement[k].split("=");
    nameValue[tmpArray[0]] = tmpArray[1];
    return nameValue
    var srchData = decodeSearchString();
    </SCRIPT>
    However, now I need to add the value returned from the above srcipt to the Java script listed below:
    <SCRIPT Language="Javascript" SRC="#srchData.link#?open&pID=PAR"> </SCRIPT>
    This above script if working will add the HTML from the URL query to the page, but I keep getting a Java Error with this script. Please Help !

    I assume you are using a JSP page and not just solely doing Javascript. IF you are using JSP, then read on. Otherwise, I can revisit your script.
    To obtain the value of the query string, you would use a method call such as:
    String strQuery = request.getQueryString()
    Or, to get a single parameter off the query string, you can call:
    String strSearchData = request.getParameter("paramname");
    Or, if you want all the parameters and values instead of just one long string you can call:
    Enumeration enumParamNames = request.getParameterNames();
    You can use the above enumeration in combination with getParameter() to get the values.
    In order to build your script line and add the query string, you would then do something like this:
    <SCRIPT Language="Javascript" SRC="#<%=strSearchData%>.link#?open&pID=PAR"> </SCRIPT>
    Notice the <%= %> block in the above code.
    I hope that is what you were looking for. Your example is somewhat confusing so I may have answered wrong.
    Mike

Maybe you are looking for