Print to screen OR file problem, need help please.

Hiyo!, im doing a certain program the way to Uni wants me to do it so im using a textFile jar file for all the reading writing etc, i know its not standard java but thats not what im having trouble with.
Im trying to make a prog that will print its results to screen if the only augument on the command line is the file to read from eg.( java ProgramThree input.txt ).
but if two arguments are written on the command line eg.( java ProgramThree input.txt output.txt ) then it
will print the results to the file (output.txt) and not display to screen.
I know that its just that ive messed up a couple of the "args.length" statments in main() , but my brain gets confused easy :[
Any help would be sweet. Thanks.
class ProgramThree
        public static String calc(String line)
            String type[] = {"Valid Isosceles","Valid Equilateral","Valid Scalene","Invalid"};
            String result = null;
          int s1 = 0;
          int s2 = 0;
          int s3 = 0;
          try
               StringTokenizer st = new StringTokenizer(line);
               s1 = Integer.parseInt(st.nextToken());
               s2 = Integer.parseInt(st.nextToken());
               s3 = Integer.parseInt(st.nextToken());
          catch (Exception e) {e.printStackTrace();}
          if ((s1+s2>s3)&&(s1+s3>s2)&&(s2+s3>s1))
               if((s1==s2)||(s1==s3)||(s2==s3))
                    if((s1==s2)&&(s1==s3))
                         result = type[1];
                    else
                         result = type[0];
               else
                    result = type[2];
          else
               result = type[3];
          return result;
        public static void printScreen(String result)
          System.out.println("\nTriangle is: " +result+ "\n");
        public static void main(String args[])
          String line = null;
          String result = null;
                if(args.length > 2)
                  System.out.println("Too many Filenames Given!");
                  System.exit(1);
                textFile inFile = new textFile(args[0], 'r');
                textFile outFile = new textFile(args[1], 'a');
          while(!inFile.EOF())
               line = inFile.readLine();
               if(line == null)
                    break;
               result = calc(line);
               if(args.length == 0)
                    printScreen(result);
               else
                             outFile.writeLine(result);
                    System.out.println("\nResults written to file.");
          inFile.closeFile();
          outFile.closeFile();
          return;
}

Thanks for your reply neil!
But im not to sure how I would impliment your code into my program :0
The code that I posted before is throwing an arrayOutOfBounds exception at the line
inFile = new textFile(args[0], 'r');
outFile = new textFile(args[1], 'a'); <-----------Here
This happens if I enter none or one auguments on the command line :/
But if I enter two auguments it works fine and writes to file..
I know its because when there is one augument on the command line (or none at all) it opens to outFile for nothing, because its printing to screen?
The thing is i dont know how to fix this :[
-thanks

Similar Messages

  • Serius project problems - Need help please

    Hi,
    I'm using adobe premiere and after effects to my last film (this is not the first time). I'm using DV 1280*720 default sound settings (as I did before in other movies). I have an Imac C2D and plenty of hard disk space.
    Yesterday when I import new takes and done some light fx's (blur 10% and tint) when I saved the premiere frozen for 30 minutes and then I had to force quit.
    When I've tried to open that project again, it just don't open. I've tried everything. See if there was any corrupted file, checked for Hard drive problem (it doesn't have any) and I delete the previous rendered files (as I saw on some tutorial).
    At least I could recover that project using autosaved and previous project backup (I take care always of saving backups).
    But when I saved again (the new recovered and rendered project) it freezes on quit and there comes again. (it seems that premiere it is getting something from the old(damaged) project and just stack there !!!!!!
    The project then it just don't open (I don't see any error message) I just see after 1 hour my premiere freezed and there is no way to see the timeline to fix anything.
    I assume that I have to recover again and to all work over and over. I saw some forums talking about adobe "broken links" something related to video files source and corrupted files, but I still don't get it (since premiere doesn't tells me what is going wrong!!!!!!). They talk about deleting MACC file on windows but I'm on a mac. I didn't saw any tutorial about recovering.
    whe this thing happens I see my timeline with video and audio. I can render but when I quit the program doesn't load the project again.
    Please any help...... I'm working since a month ago on this movie and I need to deleiver that asap.
    Is it better to export the video in parts and them join in a new project or there is any other thing that I can do without missing my month of work.
    ohhh man I just want to scream

    For any reason that I can't explain when I arrived home after day work, I've tried last time before looking my backups and Premiere loaded my project
    Before save and quit I've take a look in all file (check the link and where is the source) I found 2 still frames (photos) were lost ( i mean from my hard drive).
    My biggest clue now it is, when I deleted some video file before, when I enter the premiere project 1st thing that show it is a windows asking me to "point" where is that file.
    But when happens with a photo, premiere doesn't say that this files are lost. It just stucks your project. Any tip to prevent this again?
    Hardware Overview:
      Model Name:    iMac
      Model Identifier:    iMac7,1
      Processor Name:    Intel Core 2 Duo
      Processor Speed:    2.4 GHz
      Number Of Processors:    1
      Total Number Of Cores:    2
      L2 Cache:    4 MB
      Memory:    4 GB
      Bus Speed:    800 MHz
    Intel ICH8-M AHCI:
      Vendor:    Intel
      Product:    ICH8-M AHCI
      Speed:    3 Gigabit
      Description:    AHCI Version 1.10 Supported
    WDC WD3200AAJS-40VWA1:
      Capacity:    298.09 GB
      Model:    WDC WD3200AAJS-40VWA1
      Revision:    58.01D02
      Native Command Queuing:    Yes
      Queue Depth:    32
      Removable Media:    No
      Detachable Drive:    No
      BSD Name:    disk0
      Mac OS 9 Drivers:    No
      Partition Map Type:    GPT (GUID Partition Table)
      S.M.A.R.T. status:    Verified
      Volumes:
    iMac:
      Capacity:    297.77 GB
      Available:    158.68 GB
      Writable:    Yes
      File System:    Journaled HFS+
      BSD Name:    disk0s2
      Mount Point:    /
    ps: about your question "Next, please verify your Project/Sequence Presets. Do they match your footage 100%?" I've changed 2 video files, they were pretty bigger than the part I was taking for this project, so I edit and save just the part that I am using.
    Btw I've heard that Journaled HFS+ it is not good on Imac to use premiere render option. Is that right?
    Many thanks in advance.

  • Having trouble with a audio file. Need help please!

    Hello. 
    This may sound funny and not to related to any of this at first, but if anyone here knows about the game portal, then they know about the ARG that went on during last week and may even still be continuing. None of thats really important but if anyone cares to know, basically VALVe released a new update with 30 new sounds, 26 of them moarse code/sstv pictures. 3 of them called dinosaur_fizzle 1 2 and 3. Infact, each one was named dino_1 dino_2 and so on. 
    The main sound that no ones been able to crack is called Dinosaur_noise. Its obvious there are voices in it and its some sort of major clue, this file is way out of league with the other ones. No ones solved it 100% or cleaned it enough to make basically anything audible.
    Now this started March 1st. Since then i have worked hours on the audio file. I have gotten close, but not close enough.
    Thats why im turning to someone here, that can do a through analysis of the audio that adobe or reaper just cannot do.
    In the attachments is the original file itself with no editing what so ever.
    Heres some collected data. 
    Frequencies of interest
    An analysis was undertaken to find the strongest frequencies acting within "dinosaur_noise". Linear and Logarithmic curves showed sets of dominant figures, with the most being:
    Frequency (Hz)
    Comments
    9092
    Largest spike before silence
    7862
    Very faint
    7812
    Very faint
    7657
    Very faint
    7502
    Largest spike in the 4000-9000Hz band
    3502
    various noise between 3502 and 3510
    360
    Another very visible wave. This was the most pronounced visible wave in the Logarithmic scale
    35
    The most dominant low frequency wave
    There are a few standout segments, not of voice data underneath, but visible clicks or something happening about 5 times. These could be indications of splices or other manipulations going on. The largest noticed broad-spectrum spikes were:
    Time(in samples)
    Comments
    55402
    First broad spike
    422931
    Second broad spike
    751643
    Third broad spike
    1081537
    Fourth broad spike
    1110841
    Fifth broad spike
    Silence in the frequency ranges is located in the band of 10.567 - 15.337 KHz. All frequencies above that are likely to be high frequency poinoning from the FFT process. 
    Heres what i know personally.
    -Noise reduction makes it a lot worse and adds strange harmonics and artifacts.
    -Most filters do the same.
    -Clear voice around 15 that says THATS AMAZING.
    If anyone cares to help I would appreciate it so much.
    Here are some links that might help.
    http://www.snotmonkey.com/work/school/405/methods.html
    http://pastebin.com/r90fEtnd C++ code
    Actual files in attachments 
    Attachments:
    dinonoise.zip ‏2554 KB

    LabVIEW has a sound and vibration toolkit.  Do you have that?  Do you have LabVIEW?
    The forum is made up of volunteers who will help others with their LabVIEW problems.  But you need to have a specific problem and ask clear questions.
    What you are asking for is very unclear.  Why do you even want to do a "thorough analysis of the audio"?  No one is going to do your project for you.

  • Setup Problem - Need Help Please!!

    My problem is a low hum eminating from my speakers every time I connect my MPC2000 sampler to my audio interface.
    My setup consists of the MPC2000, a Dj Mixer, and my laptop which has an M-Audio interface which I use to connect the mixer & MPC. Basically, as soon as I remove the cables that connect my MPC or my mixer to my interface, the hum stops. I've tried different cables, new cables, a ground adapter for the MPC to change it to 2 prong, and nothing helps. The only thing that DOESN'T cause this hum when plugged into my interface, is my keyboard, so i'm quite sure the interface itself isn't the problem.
    Does anyone know what might be causing this interference that's resulting in a hum? I have exhausted all my own theories and am desperate for some sort of help! Many thanks in advance!!!

    Hi beirut,
    Try the following:
    1.Put the mpc2000,the dj mixer and your computer all in the same power outlet from the wall.
    2.Go to home despot and buy a few gray-colored ground lift plugs (they must be gray)
    3.With these gray ground lift plugs,lift the MPC2000.test the system.No hum=solved problem.hum still there or different,list the DJ mixer.
    4.Is your DJ mixer hooked up to turntables? If so,you need to ground the turntables to a proper ground.Good turntables have a little wire coming out of them,just for that purpose.
    5.Try turning off any TVs,refridgerators,fluorescent lighting(the ones that look like office lights),and other things around your place,and see if the hum goes away.
    6.Try using a DI box for your DJ mixer,to plug it in to the DI,and then out to the audio interface.
    7.And Most Importantly... RUN AND BUY A DIFFERENT BRAND OF AUDIO INTERFACE!!!!!!!!!! M-Audio...yucky yucky yucky!!!
    Cheers

  • Well last night after I had got off the phone it had froze up (never happened before) and then it it went blank. I would call it from my house phone and it would ring and vibrate but nothing showed up on the screen. I just need help please :(

    Well last night after I had got off the phone it had froze up (never happened before) and then it it went blank. I would call it from my house phone and it would ring and vibrate but nothing showed up on the screen. I don't know where to go from here I just need desperate help. Please and thank you!

    Try doing a hard reset, Hold the "Home & Power Buttons" down at same time, until you see the Apple Icon appear. Then let go of the buttons.

  • Nokia n96 video problems.Need help please

    how do i go about putting videos on through pc suite but everytime i try, it starts converting and stops quatre way there.
    i tryed using another media converter all together now don't know what format or resolution the videos have to be converted to in order to work on my phone. the videos i have been trying to convert are .avi format.
    does anyone have any advice that can help me?

    PC suite is the wrong tool for this job as it's not very good at handling large files.
    A great source of information on how to make videos compatible with the N96 is available on this blog:
    http://portablevideo.blogspot.com/
    Look through the archives on there and you will find a very good guide on what programs to use and the required settings.
    If your avi files are divx or xvid you may want to install the programs below to see if you can play them without conversion. The program on the first link is free, the second is not but a demo may be available.
    http://labs.divx.com/system/files/private/DivXPlayer_S60_3rd_0.sisx
    www.lonelycatgames.com/?app=smartmovie
    Message Edited by psychomania on 20-Jan-2009 09:02 AM

  • EMU 0404 Problems -- need help please

    Any help to my current issue would be greatly appreciated.
    I recently bought the EMU PCI card on its own.
    Im runnin a brand new top of the range pc on windows XP (im new to XP, windows 2000 and a mac user originally - so i may have just missed something)
    But on my old windows 2000 machine with the standard on board soundcard, when i went to my sound settings (speaker in the corner) then, Properties > Recording....... i got a list of several options, such as - Line in, Stereo mix, wave out, etc...
    In the past i used the stereo mix setting to stream music to potential customers via msn messenger, obviously streaming what my soundcard played.
    After installing this soundcard, i now have no stereo mix or anything previous, only WAVE which i cant select or control the volume for, maybe because its on xp?? is there a way to record and stream (via msn) what your soundcard plays using the EMU 0404? i also used this setting to record sounds of the internet etc... Surely im being stupid? with an expensive upgrade to this soundcard from crappy on board? surely?
    If so any help would be massivly appreciated...
    Thanks in advance

    Thank you for you speedy reply mate.
    Ive read the link you provided aswell as several other sites and the manual.
    For some reason having the emu selected and enabled in the hardware settings instead of the on board soundcard it takes away all the recording settings in windows as i mentioned before.
    Simply i can record with this soundcard, i just want to stream what my soundcard plays through msn, also wherever i look the only option for playback and recording i have is E-DSP Wave [Df00]....... ive gone throughout the patchmix, tried near every setting to stream what my soundcard plays.. im lost
    cheers

  • C6-00 email account problems, need help please..

    Hi all. First of all, I don't experience any issues with the email accounts as referred to in other posts here. I do however have one problem and would appreciate if someone could explain a work-around for the issue. I'm desperately trying to set up a Gmail account using IMAP protocol but that allows me to access all advanced settings and not the ones pre-defined by the Nokia software. I'm basically wanting to have the same control I have over non pre-configured email provider accounts, download limits in KB, constantly connected when i have the mailbox open, choosing what folders to sync or not, etc.
    I did manage to have a Gmail account configured this way by mistake. When i set up the account it gave an error informing me of that i could try to continue with "alternative settings without the Nokia personalization" sort of (don't remember really the message) and after accepting to continue the account was created with "standard IMAP" settings.
    I'm however unable to re-create the event and simply cannot create a Gmail account with those settings. Even tried to set up another existing account and then edit definitions to Gmail but the personalized settings are always taking priority.
    Any advises please? Thanks alot in advance and best regards!
    Fredrik
    P.s. Sorry for double post. Mozilla Firefox messed up my 1st post

    Same problem here, but with error -2096. Can connect fine on same network with an iPod Touch and a Macbbook, but the Mac Mini that normally connects to iTunes just won't connect. Not using multiple accounts, uninstalled iTunes 8, reinstalled 7 - no joy. Uninstalled 7 reinstalled 8, no joy. Updated 8 to 8.01, no joy. Tried putting the Mini into a DMZ on the router, still no good. Sent an email to Apple support who will needless to say tell me to reinstall iTunes 8......
    Not working for me as of 10/10/08.

  • Zen Micro problem need help

    Today i was listening to music and my zen micro just froze while playing and no buttons could be pressed and the lock button wasnt on. So i took the battery out and rebooted the player but it froze at the creative screen. I went home and i went to recovery mode and tried to reload the firmware but it said erasing firmware for more than 2 hours. So then i tried a format but it said formating for the same amount of time. I need help please. Also, recently i've had problems witht the headphone jack. When ever i would stick it in it would sound distorted and i would have to move it around until i got it to a certain spot to hear it good again. If anyone else has this problem please tell me. One more thing i had returned my other micro zen in for hard dri've probems and this was my new one do u think if i have to return in (hopefully not) that they would accept it.

    If the functions in Rescue Mode aren't working properly then you need to contact Creative Support.

  • In installation process of Acrobat Professional 7 , its showing that Adobe Pdf printer is not Installed...need help to install the software completely

    In installation process of Acrobat Professional 7 , its showing that Adobe Pdf printer is not Installed...need help to install the software completely

    If it is Win 7 or later, the Adobe PDF printer for AA 7 will not install and AcroTray will not function. You will have to install a PS driver from Adobe or maybe an HP color PS printer driver. Then edit the driver properties and change the name to Adobe PDF and the port to FILE. You will always have to do an extra step in creating PDFs by opening the file that is created in Distiller to get the PDF.
    If you are talking about Win 8, you may not be successful at all. If you got Acrobat and Distiller to install, then there is a chance.

  • My MBP didn't recognise my password, started it in safe mode, I can see my files, but I don't know what to do next, as the image of reset password isn't selectable. I just moved from PC. Need help please...

    My MBP didn't recognise my password, started it in safe mode, I can see my files, but I don't know what to do next, as the image of reset password isn't selectable. I just moved from PC. Need help please...

    Safe mode is not what you want in this case. Reboot to recovery mode - hold down cmd-R as the Mac reboots. Go past the language-selection screen, click the Utilities menu, then Terminal. Type:
    resetpassword
    Followed by the return key, and follow the prompts. Reboot normally when done.
    Matt

  • My iPad shows a message "Cannot find AirPrint printer". I used to use my iPad to print materials using HP wireless printer D110. Now it does not want to print. Is this because I am now using IOS 7? What should I do to solve the problem? Help please.

    My iPad shows a message "Cannot find AirPrint printer". I used to use my iPad to print materials using HP wireless printer D110. Now it does not want to print. Is this because I am now using IOS 7? What should I do to solve the problem? Help please.

    Restart your WiFi router and printer by removing power for 30 seconds.

  • After my iphone4S update to 7.0.6, it have a problem that keep searching network then no service show on display. Can't call. I have try check sim card, reset network settings, and restore my iphone. Still not working at all. Need help please.

    After my iphone4S update to 7.0.6, it have a problem that keep searching network then no service show on display. Can't call. I have try check sim card, reset network settings, and restore my iphone. Still not working at all. Need help please.Urgent.TQ

    Izit software or hardware? Confuse:(
    Only can use wifi now.
    Any way thanks guys for ur suggestion:) amishcake and simes

  • TS1702 Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

    Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

    Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

  • How do you overlap PDF's and finish with one PDF file? Need help ASAP

    how do you overlap PDF's and finish with one PDF file?
    Need help ASAP

    I'm not sure if you can do that with CreatePDF.  Try it; you got one free use when you sign up with Acrobat.com
    If not, you will have to use Adobe Acrobat; there is a full-use 30 days trial.

Maybe you are looking for

  • Using cl_gui_alv_grid class in report , but when no data , entire session closed ?

    Hi , I am using cl_gui_alv_grid for one of my report . It is working fine when there are reocords , but when there is no record entire session will be closed from selection screen itself. Having class with data /method declaration and an event class

  • Basic Runtime for VS 2008

    I have a report that I designed in Crystal 10.  The report runs with no problems from within the designer.  However when I try to run the report in my .NET application and export to a PDF I have no luck.  The report engine just hangs.  I have a diffe

  • L/R is not previewing photos from Canon 70D SD Card photos

    L/R 4 will no longer read raw file images from my Canon 70D Import says "Preview unavailable for this file." It will only read JPEG images. I've recently purchased the Canon 70D It was working fine with the Canon ti1

  • What add on do i need to remove to stop the following error

    keyword Add-on![Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getCharPref]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: chrome://keywords/content/overlay.xul :: <TOP_LEVEL> :: l

  • Unable to mount exfat after updating: libutils-linux 2.25-3?

    Hi everyone! I have just updated my system and libutils-linux has been upgraded to version 2.25-3 from version 2.24.2-1. The problem is: after the update, I could not mount my exfat device: some errors occur. In details: 1- The device is a Truecrypt