Having trouble Output streams and text formatting???

Salutaions!
I'm trying to write a peice of code that takes input from a file and outputs it in the following way: (1)Any string of two or more blank space is replaced by a single space. (2)All sentences start with an uppercase letter. Define a sentence as beginning after a ".", "?","!"
This is what I got: Please help!
import java.io.*;
import java.util.*;
public class Empty
private static boolean cap;
private static DataInputStream input;
private static DataOutputStream output;
private static String inputFile, outputFile;
public static void main(String[] args) throws Exception
     input = new DataInputStream(new FileInputStream("a://in.txt"));
     output = new DataOutputStream(new FileOutputStream("a://out.txt"));
     char thisChar, lastChar = ' ';
     while(input.read() != -1)
     thisChar = ((char)input.read());
     if(lastChar != ' ' && thisChar != ' ')
          if(thisChar == '.' || thisChar == '?' || thisChar == '!')
          {    cap = true;
          output.writeChar(thisChar);
          lastChar = thisChar;
          else
          cap = false;
          output.writeChar(thisChar);
          lastChar = thisChar;
     output.close();
     input.close();

one clear mistake i can see in this method is that you r calling input.read() twice every time. once in the if(input.read()..) statement and then in the statement
thisChar = ((char)input.read());
the byte read the first time is not captured anywhere.
do you have some specific motive behind doing this?
luck!
y

Similar Messages

  • I am having trouble sending pictures in text messages to anyone whether its a iphone user or not. Anyone know why? It just keeps saying not delievered

    I am having trouble sending pictures in text messages to anyone whether its a iphone user or not. Anyone know why? It just keeps saying not delievered

    Had the same problem a while ago. Call your mobile operator and they should guide you. It is some numbers that varies from each phone operator...

  • HELP !!!I want to give my old apple to my girlfriend, SO SHE CAN PLUG IN HER NEW IPHONE, CREATE AN APPLE ID AND USE MY OLD LAPTOP TO DOWNLOAD itunes music, but im having trouble deautherizing it, and making her the OWNER, IF you get my drift, how to i mak

    Hi
    I have a new powerbook and want to give my girlfriend my old G4 power book, she has a new iphone 5s, and wants to create a new itunes/apple id. When i try to de authorize the G4 and sign in with her new apple ID it says bad password, how can i release the G4 from my cluster of authorized apples and make her the owner so she can download music and more importantly sync her music with her phone, she only has 3 songs on her iphone, and loaded all her CD's into the g4 but cant sync, im no dummy and this shouldnt be hard, but its driving me crazy!!!!!!
    thx u so much for your time heeeellppppp.

    Perhaps, as we have the same music tastes, for now i should just authorize her phone to my power book just to sync music, not pics, contacts etc? I'd hate to overright her contacts etc lol????
    HELP !!!I want to give my old apple to my girlfriend, SO SHE CAN PLUG IN HER NEW IPHONE, CREATE AN APPLE ID AND USE MY OLD LAPTOP TO DOWNLOAD itunes music, but im having trouble deautherizing it, and making her the OWNER, IF you get my drift, how to i mak 

  • Just bought a new iPhone and am having trouble with iTunes and App Store. I can log in to Cloud, iTunes, and app store but once I try to download, it says "Youe apple id has been disabled". I've reset my password three times and have no issue on my Pad.

    Just bought a new iPhone and am having trouble with iTunes and App Store. I can log in to Cloud, iTunes, and app store but once I try to download, it says "Youe apple id has been disabled". I've reset my password three times and have no issue on my Pad.

    Hi FuzzyDunlopIsMe,
    Welcome to the Support Communities!
    It's possible that resetting your password multiple times has triggered this security.  Click on the link below for assistance with your Apple ID Account:
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Here is some additional information regarding your Apple ID:
    Apple ID: 'This Apple ID has been disabled for security reasons' alert appears
    http://support.apple.com/kb/ts2446
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Click on My Apple ID to access and edit your account.
    Cheers,
    - Judy

  • Several of us have a iPhone 6s and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Several of us have a iPhone 6plus and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Not having the problem, don't personally know anyone who is.

  • Having trouble adding purchased and imported music to my playlists

    I'm having trouble adding purchased and imported music to my play lists. For example when I purchase or import new music to my playlists I have to re sync my ipod or the new songs don't appear on my playlists. Perhaps this is because I once unplugged my ipod w/out first disconnecting it. Previously when I purchased and imported music songs would appear on my play lists when I dragged them from purchased to playlist.

    Remember to authorise your new machine with the Apple ID
    Essentially copy the itunes folder and all sub folders over to the same place in the new computer.
    Windows XP: C:\Documents and Settings\username\My Documents\My Music\iTunes\
    Windows Vista: C:\Users\username\Music\iTunes\
    Windows 7: C:\Users\username\My Music\iTunes\
    Windows 8: C:\Users\username\My Music\iTunes\

  • Having trouble opening connections and reading from Bluetooth devices.

    Hello,
    As the title states, I am having trouble opening connections and reading data from a Bluetooth device. We are using a PDA to communicate with LabVIEW. First, the Bluetooth Open Connection VI displays a timeout error half of the time. Second, when it does open, it does not read what the PDA is sending. Third, if it does allow an open connection, it will not do it a second time unless the devices are turned off.
    I also have another related question. I am using a Linksys Bluetooth USB adapter, and the driver is proprietary. Labview requires the use of a Microsoft driver, and we are having problems going back and forth between the drivers. What Bluetooth receiver would you suggest using? The reason I ask is the fact that you have Bluetooth examples of client VI's. Therefore, you must use a similar device. Thank you for your time.
    -Jon

    Hi Jon,
    I'm not sure what Bluetooth receivers were used to verify the functionality of the VIs. However, I still want to help you solve your issue. Please make sure that you are running the shipping examples and let me know what version of LabVIEW, what PC OS and what PDA OS you are using. Does the Microsoft driver work for your Bluetooth receiver if you uninstall the Linksys driver?
    With your answers I'll do my best to help you out.
    - Philip Courtois, Thinkbot Solutions

  • I am having trouble updating minomonsters and I would like to find a way to fix it without erasing all of my data from the app.

    I am having trouble updating minomonsters and I would like to find a way to fix it without erasing all of my data from the app.

    I am having trouble updating minomonsters and I would like to find a way to fix it without erasing all of my data from the app.

  • HT1222 I am having trouble downloading Itunes and Safari.  I keep getting a windows installer error

    I am having trouble downloading Safari and Itunes.  I keep getting a windows installer error.

    Try temporarily disabling your firewall and antivirus software and try again...
    See here for Connection Issues
    http://support.apple.com/kb/TS1379
    From Here
    http://www.apple.com/support/itunes/troubleshooting/

  • I'm Having trouble with OWA and Certs after the Rollup 7 for SP3 installation. any idea? update 2961522-

    Hi, everyone.
    I'm Having trouble with OWA and Certs after the Rollup 7 for SP3 installation. any idea? update 2961522-
    after running get-OWAVirtualDirectory or test-OWAConnectivity i'm getting a message that says "OWA it's Orphan, No Metadata information can be found."
    I only have the OWA users impacted.- anywhere users, and ActiveSync are working well.-
    Thanks,
    Fabian Alberto Campo
    MCT-MCSA 2012-MCITP365-MCTS
    Fabián A. Campo H. Consultor tecnico @ IXO Ltda. MCT MCP MCTS MCSA HP-APS Cra. 67 No. 167 – 61 of 303 Bogotá, Colombia

    Hi Fabian,
    Is there any error code when user access their mailbox on OWA. Please confirm if there is no results returned in EMS when you run Get-OWAVirtualDirectory cmdlet. Also check whether there is any Event Logs related to OWA in Exchange.
    In IIS manager, make sure the OWA virtual directory is listed in the Default Web Site. In EMC, we can navigate to Server Configuration > Client Access, select server and turn to Outlook Web App tab. Then we can click Reset Virtual Directory in the right
    Actions pane to reset OWA virtual directory.
    Additionally, please restart IIS service by running iisreset /noforce from a Command Prompt window.
    Regards,
    Winnie Liang
    TechNet Community Support

  • Having trouble scanning pictures and sending to computer

    Having trouble scaning photos and sending them to my computer. I have HP Envy 700-300z DT.  Printer is a officejet all in one. Printer does everything it should do except scanning to send to computer.

    Hi,
    You may have to start from your computer first:
        Double click printer icon on desktop,
        Select Manage Scan to Computer
        Click Enable -
    You can start this automatically with Windows BUT you will get an arror message if you  turn on the computer BEFORE the printer.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • I have an iPhone and just goy I pad but no computer I'm trying to synch them together but having trouble with iCloud and I can't seem to subscribe for iTunes match from either devise

    I have an iPhone and just goy I pad but no computer I'm trying to synch them together but having trouble with iCloud and I can't seem to subscribe for iTunes match from either devise

    You first have to subscribe to iTunes Match through iTunes on your computer and have your music library in iTunes uploaded/matched before you can enable it on your iOS devices (see http://www.apple.com/itunes/itunes-match/).  Without a computer you won't be able to use iTunes Match.

  • Purchased LaCie external to backup having trouble setting up and getting started

    external to backup having trouble setting up and getting started

    Okay, first you will need to setup time machine to backup your system to the new hard drive.  Just open time machine and turn it on, then select your new hard drive and time machine will start the backup in a few minutes. 
    Take a look at this link, http://support.apple.com/kb/HT1427

  • Having trouble loading ATT and CenturyLink sites with safari now, anyone else having this problem?

    having trouble loading ATT and CenturyLink sites with safari now, anyone else having this problem?

    Howdy MacRocker,
    Thanks for using Apple Support Communities.
    To start with troubleshooting an issue like this where you're unable to load certain websites in Safari, I suggest that you clear out your browser history and website data.
    Safari 8 (Yosemite): Clear your browsing history
    Happy Holidays!
    Alex H.

  • Why am I having trouble loading apps and updates on my iPad? I have closed out all my apps and rest my iPad but still no luck. Can someone help me please

    Why am I having trouble loading apps and updates on my iPad? I have closed out all my apps and rest my iPad but still no luck. Can someone help me please?

    Try a reset, press and hold both the home and power buttons for 10-15 seconds till the Apple logo appears. Release both buttons. Wait 15-20 seconds till your iPad starts on it's own.

Maybe you are looking for

  • Message to Creative La

    Dear Creative Labs: As a once valued customer I now feel completely betrayed by your unlawful and unethical business pratices. While as a former Aureal user, I turned a blind eye chalking it up to Aureal being careless. However after reviewing your b

  • Shuffle 1st gen works only in usb port, 2nd gen shuffle isn't noticed

    I am aware these problems have not been solved anywhere on the internet but im praying someone has the answer to it.....maybe even someone from apple (but i dont think they care) Lets start with my 1st gen shuffle 2 years ago it was accidently washed

  • Which one is better to use..Canvas or J2ME Polish

    Hello Frnds, I want to add background images n want to use High level GUI, So is the polish be a good option for it , or should I go for simple j2me canvas n write my own low level... GUI like construct .....or should go for Synclast 3rd party API. l

  • I can't install Flash Builder.How should I do?

    Here is error message: Exit Code: 6 Please see specific errors below for troubleshooting.For example,  ERROR: DW030 ...   -------------------------------------- Summary --------------------------------------  - 0 fatal error(s), 1 error(s)   --------

  • IPod stops playing

    IPod touch stops playing after a minute. Have to unlock and press play again. Anyone know how to fix?