JUSTIFYING TEXT! ANY help NEEDED

hello,
I am writing a program for a high school java class, and our teacher is asking us to use the stringtokenizer to manipulate text being inputted(sp) by right-justifying it as an output. I have managed to use the stringtokenizer to seperate each word into an array, but I am a little confused as to how I should go about arranging my words with spaces using for loops etc.....hereis what i have so far:
import Keyboard;
import java.io.*;
import java.util.*;
class Justify {
// This method is passed a string 's' that contains several
// words separated by spaces. It creates an array called
// 'list' that contains each word in 's.'
public static void pullApartWords (String s, String[] list) {
     // Make 's' a StringTokenizer object
     StringTokenizer words = new StringTokenizer (s);
     // Create an array to hold the tokens
     // ** Note that we cannot do "new" here, or else it loses
     // the reference from the main method. **
     // list = new String[words.countTokens()];
     int count =0; // Counts each token
     // As long as there are more tokens in 'words,' put
     // the next token into the 'list'
     while (words.hasMoreTokens()) {
          list[count] = new String (words.nextToken());
          count++;
     // This method shows how the 'pullApartWords' method could be
// used. It creates a string, and calls the 'pullApartWords' method
// to create an array containing the words in this string. It
// then prints out the words in this string.
public static void main (String[] args)
throws java.io.IOException
     //String line= Keyboard.readString();
     System.out.println("Please enter text to justify");
     String line = Keyboard.readString();
     String sentence = "This is the sentence to be broken up into tokens.";
     String[] tokenArray; // This array will store the tokens
     tokenArray = new String[new StringTokenizer(line).countTokens()];
     // Takes each token in 'sentence' and puts it into the 'tokenArray'
     pullApartWords (line, tokenArray);
     // Output Section
     System.out.println ("The sentence is:");
     System.out.println (" "+line);
     System.out.println ();
     System.out.println ("There are "+tokenArray.length+" tokens in the sentence.");
     System.out.println ();
     //Print each token in the 'tokenArray'
     for (int i=0; i<tokenArray.length; i++) {
     System.out.println (" tokenArray["+i+"] = "+tokenArray);
     //for (int i= 0; i<tokenArray.length; i++)
          System.out.println(tokenArray[i])
any suggestions at all? anything would be helpful ...thanks

Here's something to play around with
import java.io.*;
import java.util.*;
class RightAlign
  String words[];
  public RightAlign()
    try
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Please enter text to justify");
      pullApartWords(br.readLine());
    catch(Exception e){}
    System.exit(0);
  public void pullApartWords (String s)
    StringTokenizer word = new StringTokenizer (s," ");
    words = new String[word.countTokens()];
    int count = 0;
    while (word.hasMoreTokens()) words[count++] = word.nextToken();
    display(s);
  public void display(String s)
    System.out.println ("The sentence is: " + s);
    System.out.println ("There are "+words.length+" tokens in the sentence.");
    String pad = "                         ";
    for(int i = 0; i < words.length; i++)
      System.out.println((pad+words).substring(words[i].length()));
public static void main (String[] args) {new RightAlign();}

Similar Messages

  • I had a contact added mistakenly as an iphone contact now it tries to send imessages to that contact instead of a regular text, any help?

    I had a contact added mistakenly as an iphone contact now it tries to send imessages to that contact instead of a regular text, any help?

    Something doesn't make any sense here, because iMessage ONLY works between you and anyone using an iPhone, iPad, or iPod touch with iOS 5, you couldn't iMessage someone that DIDN'T meet those requirements, if you wanted to. Are you positive this contact does not meet the requirements to iMessage?

  • SPRY submenu text color help needed.

    I've created a vertical SPRY menu bar over a dark background
    image in a left sidebar. The text is white and the background is
    set to none (transparent).
    When the submenu opens to the right it's on a white
    background (over the main content area). Because the text is set to
    white, you cannot see the submenu links.
    Is there a way to change only the submenu links to black? I'd
    also like to change the background color of the submenu links.
    Thanks in advance for your assistance.

    http://labs.adobe.com/technologies/spry/home.html
    - This first link is the Spry home page. There you will find an
    updater to Spry that if you have not downloaded up to this point,
    you should I will explain why shortly. Inside the package you will
    find a ton of samples and an Extension. Install the Extension and
    restart DW. Then under the Sites menu you will see a new option to
    update your Spry. Run that updater.
    http://labs.adobe.com/technologies/spry/samples/menubar/MenuBarSample.html
    - This page will show you how to make the necessary customizations.
    The last two examples will help you out. All you will need to do is
    read through the source code of the document. There is no need to
    read through the source of the CSS file because they show you the
    changed CSS on that page. Just apply those changes to your CSS
    SpryMenuBarVertical.css document where the tag matches. If there is
    no matching tag you will need to just copy and paste the entire
    portion but I don't think that is the case with your menu. Also
    your entries will be Menubar 8 & 9 in the source code, but to
    find the matching code in your css document just replace the
    MenuBar8 or 9 with MenuBarVertical.
    If you have not done a lot of work with CSS before I would
    highly recommend reading this tutorial before going through any of
    the above steps:
    http://www.w3schools.com/css/

  • Need to add superscript for text field--HELP NEEDED.

    Hi Friends,
    Is there any way to implement superscript and subscript text in Crystal?  For example, I would like to superscript the portion (1) of the following string:
    "Buy(1) or Sell(1)"
    The only way I have found to do this is to put the "235" in a separate text field that uses a smaller font size, and overlay it into the gap that I intentionally left in the larger text field.  For display and printing purposes, this works OK, but if a report containing these strings is exported to Excel, the text fields are exported as separate cells, which makes the exported report look funny.
    I can create this string in Word, then cut and paste it into a text field in Crystal (which initially seems to work), but as soon as I click off the field, all the characters in it are converted to the same font size.
    If this can't be done in the current version of Crystal, are there any plans for it to be implemented in future versions?

    hello all,
    the text interpretation for html or rtf in fields will not render superscript or subscript. the basic rule is that whatever you can format directly in a crystal reports text object, that's what you can have interpreted.
    look up "text interpretation html" in kbase for a full list.
    one option is to turn html passthrough on the server in question if this is a huge deal for you...if you want instructions on how to turn html passthrough on, they are located in the webelements user guide at
    http://diamond.businessobjects.com/node/255
    after doing so, you'd drop the database field into a formula and any html in the database field would be interpreted.

  • TS2755 i put a new sim from vodaphone into my iphone but cannot send or receive photos with my texts, any help

    i put a new vodaphone sim into an iphone and all is great except i cannot send or receive photos with my texts

    Have you tried contacting Vodafone to make sure MMS messaging is enabled on your account?

  • After updating my iphone 4 to ios 5 i cant send or recieve text any help?

    sdg

    Go to settings - general. - cellular  my iPhone can't stop it from searching and I m sure it is using up my battery life

  • Help needed with referencing single Excel cells and formatting resulting text

    In InDesign CS5 I am putting together a 20pp catalogue of about 200 products. The plan is to have the product information, SKU code, quantity etc fixed, but have the prices (there are two i.e. pack price and individual price) being linked to an Excel spreadsheet. This is so that the prices can be updated in the Excel file and the InDesign file will pull the new prices through. In case you are wondering why I don't pull the whole set of information through, this is because there are a lot of copywriting changes done to the information once it's in InDesign - it's only going to be the prices that will be updated.
    I am planning on having two single cell tables in their own text frame, duly formatted with cell style, table style and paragraph style for the two price variables. This I am then going to have to repeat 200 times making sure I link to the next row down in Excel. This is going to be a hideous task but I see know way of modifying the cell in InDesign to point it to the next row in Excel. That's my first problem.
    My second problem is this. In the Excel sheet, the prices are formatted as UK currency and are therefore like this...
    £2.00
    £0.40
    £1.43
    £9.99
    £0.99
    £0.09
    What I will require is once I import that data (and refresh the data via a newly saved Excel file) is that the prices end up like this...
    £2.00
    40p
    £1.43
    £9.99
    99p
    9p
    So if the value is lower than £1.00 it needs a trailing 'p' added  and the leading zero and '£' sign stripped off. If the value is lower than £0.10 it also needs the zero after the decimal point stripping off.
    Then formatting wise, the '£' sign needs to be superscripted and the same for the 'p'. This I am assuming could be done via GREP?
    In summary, can anyone help with the first task of referecing the Excel cells on a cell by cell basis, given that it is the same cell column each time, but the next row down, and also point me in the right direction of the price formattting issues.
    Any help will be gratefully received.

    I would do this:
    Create on line with the formatting.
    Export as InDesign tagged text (TXT)
    Read out these tags
    In Excel exists a function to connect text from several cells and predfined text, there connect the content from cells with the paragraph styling tags. Do it in a seperate sheet. (Better would be to use a database like Access, there you can link your Excel sheet).
    Export this sheet as txt file
    Place this sheet as tagged text (there is an option in one of the sialog boxes).
    In preferences  < file handling you can specify that Tablecalculation Sheets and text is not embedded but linked, turn it on.

  • Help needed sorting a text file.

    I'm trying to simply open a file, which is a text file of a list of names, then sort that file, the print the sorted file. The problem is that I keep getting this error
    Exception in thread "main" java.util.NoSuchElementException: No line found
         at java.util.Scanner.nextLine(Unknown Source)
         at pro.NamesFile.main(NamesFile.java:36)
    Which is at this line[b] words= new String(inputFile.nextLine());
    It's not reading any lines from the file and I can't figure out why.
    Here's the rest of my code:
    public class NamesFile {
         public static void main(String[] args) throws FileNotFoundException {
              Scanner inputFile;
            inputFile = new Scanner(new File("C:/Documents and Settings/Cougar/Desktop/New Folder (2)/names.txt"));
            String name;
            inputFile.next();
            String[] words = new String[100];
            while (inputFile.hasNext()) {
                 name = inputFile.nextLine();     
                 for (int i = 0; i < words.length; i++) {
                      words[i] = new String(inputFile.nextLine());
            Sort2.insertionSort(words);
                 for (int index=0; index < words.length; index++)
                    System.out.print(words[index].toString()+"\t");
    }Here the sort algoritm I'm using, it the insertion sort one.
    public static void selectionSort (String[] list)
               int min;
               String temp;
               for (int index = 0; index < list.length-1; index++)
                  min = index;
                  for (int scan = index+1; scan < list.length; scan++)
                     if (list[scan].compareTo(list[min]) < 0)
                        min = scan;
                  // Swap the values
                  temp = list[min];
                  list[min] = list[index];
                  list[index] = temp;
            public static void insertionSort (String[] list)
               for (int index = 1; index < list.length; index++)
                    String key = list[index];
                  int position = index;
                  //  Shift larger values to the right
                  while (position > 0 && key.compareTo(list[position-1]) < 0)
                     list[position] = list[position-1];
                     position--;
                  list[position] = key;
            }I'm still relativly new at this, so forgive me if there's something obvious that I'm missing.And thanks for any help anybody can give me.

    You haven't gotten to running the sort yet, so I didn't even check that the sort routine is correct.
    Your problem is:
    You say inputFile.hasNext() once, and then you read 1 line from it. Then, in your 'for' loop, you read 100 lines from it. So, you always attempt to read 101 lines, even if the file is shorter than that.
    You should call "hasNext" before each call to "readLine". Also, you probably want a "while" loop, instead of a "for" loop, since you don't know how many words you will have. I assume you are expecting 100 or less (based on your array size).
    Two more notes:
    1. Don't do "new String(inputFile.readLine())". All you need is:
    words= inputFile.nextLine();
    2. You don't need toString here:
    System.out.print(words[index].toString()+"\t");words[index] is already a String, and concatenating the "\t" to words[index] would create a String, anyway, no matter what type words[index] was. And, calling:
    System.out.print(words[index]);would also automatically call "toString", even if words[index] were not a String.
    You could avoid creation of new Strings by:
    System.out.print(words[index]);
    System.out.print("\t");Just make sure you add braces around them, if both lines are the body of a 'for' loop. You should also make the second 'for' loop into a 'while' loop, using a counter that you update as you read the lines--so that you don't process the "null" elements of the array. You also need to account for null elements in your sort method.

  • Text help Needed!

    Hi there, I have an issue hopefully someone here can help me with- I'm working with a cousin on a Flash project, changing a few graphics. Now, I'm using Flash CS4 on a Mac, and a font used in the original file, ''Micra'' is not on my system. I used the Font Mapping function to change the font, but I still see no text when I scroll through the movie in Flash, or when it is now published. Is there anything I can do to make the text visible? What am I missing? Do I need my cousin to do anything for me? I've searched around but haven't found a solution otherwise. If it helps, I had an issue with another graphic that needed to be deleted; I couldn't see it at all and could only get rid of it by deleting it from the library. Maybe that was also due to this font issue. And to add, the movie looks somewhat different when I view it in Flash; there are other graphics that pnly show when the file is published, and I get compiler errors relating to syntax. I'm not too experienced with Flash, so I have no idea how to identify the issue.  Much thanks for any help.

    Post script- My cousin has no access to any resources I might need, and I tried installing ''Micra Normal'' on my computer. Nothing that's been made invisible so far has become visible. I can imagine a myriad of technical reasons why the text might not be showing up, still hoping someone here might have an answer. The way the text works in the Flash, there are buttons to click through the text. The text fades in with each frame. Within Flash itself I cannot see this action happening, I have no clue why. The font in the original Flash doesn't even seem to look like 'Micra', from what I can tell. My cousin sent me a packet that included a .txt file with all the text that's supposed to go into the Flash, with html code included. Dunno if there's a way I should utilize this in Flash.

  • Any ideas how I can insert a pdf into word, using the insert object option. However the pdf i want to insert has text and lines annotated, but once inserted the comments don't appear????  any help would be greatly appreciated.

    Any ideas how I can insert a pdf into word, using the insert object option. However the pdf i want to insert has text and lines annotated, but once inserted the comments don't appear????  any help would be greatly appreciated.

    You will need to find a forum for MS Word since that is the software that you are trying to manipulate in this.  If you think the processing/creation of the PDF plays a role then you should ask in the forum for the software that you are using to create the PDF.
    This forum is for issue regarding downloading and installing Adobe trial products, so in any circumstance, your issue does not fit in this forum.

  • Trying to knockout an outline stroke ONLY out of text...NEED HELP!!

    Hi All,
    First of all thank you very much in advance for any help on this. I run a screen printing business and I recently added some simple design services to my clients to bring in more business and help some people out.
    Haven't run in to any major speed bumps until now...I'm thinking everyone is going to tell me what I'm trying to achieve is out and out EASY but I need some help for a run I'm doing this week.
    I have attached the graphic which is a mock up of what I'm trying to do with the text.
    Basically, I'm looking to have the white knockout to the background color (i.e. the shirt color)
    I think I just set up incorrectly in Illustrator and that's what's giving me all the problems...if anyone could tell me how I should set this up so that I can achieve the look I'm going for it would be MUCH appreciated!!!
    If you look at the image you should be able to see what I mean, it's a black text in the center, a (what should be) knockout outline of that black text and then another black outline outside of that...please let me know if you have any questions or if you can tell me how to set it up, order and arrage the text so I can simply keep the look of the white knocking out to the shirt color.
    THANKS!
    John

    Pound,
    Assuming…:
    The black and green are defined as spot colors.
    The white is just Illustrator's default white; not a spot color, and is not set to overprint.
    …the you don't need to do anything. The white already knocks out the green. The white is not an ink. White means "no ink."
    Simply print the job as color separations. The Black will be on one sep; the Green (assuming it's spot color) will be on the other. There will be no white separation, and the white areas will not appear on either the green or the black sep.
    Remember: Yes, in screen printing you print separations as positives. But those positives are used to expose the screens; the screens themselves are the negatives. The negaitve screens in turn result in a positive on the substrate. What is white on a negative? Black.
    JET

  • Installed update (11.0.08). App still crashes if I try to edit text and images. Any help?

    Installed update (11.0.08). App still crashes if I try to edit text and images. Any help?
    1)Specs:  Alienware M17 R4 (laptop)
    GPU: GeForce GTX 675M
    CPU: Intel(R) Core(TM)  i73840QM CPU @ 2.80GHz
    Memory: 16GB RAM (15.89 GB available)
    Resolution: 1920 x 1080, 60Hz
    OS: Windows 7 home premium
    2) There is no error message. Acrobat simply closes on me without warning. The program stays open for a brief time, but then closes at random.
    3) I have tried running it as an admin, but it does not change anything. The program still closes without my consent.
    4) I have tried installing and reinstalling multiple times. It does not work even if I do not get the update (11.0.08)
    Thanks,
    hiimwill

    In that case we might want to have a look at the crash logs to check what is failing.
    How to create a user-mode process dump file in Windows Vista and in Windows 7
    http://support.microsoft.com/kb/931673
    Also please be aware that if you are using a 64-bit system you need to follow a different procedure to collect the DMP file to avoid us getting  this error from the IDE when attempting to view the file “Debugging a 64-bit dump of a 32-bit process is not supported, please collect a 32-bit dump of a 32-bit process."
    You can get the correct dump by going to the location referenced in this blog excerpt:
    http://blogs.msdn.com/b/amb/archive/2011/05/12/do-not-collect-32bit-process-dumps-with-64b it-task-manager.aspx
    So, you need to use 32bit debugger, if you would like to collect a dump of a 32bit process. So, if your process is 32bit, then you need to run 32bit version of the task manager on a 64bit OS. 32bit task manager is located in C:\Windows\SysWOW64 folder and the name of the file is taskmgr.exe.
    Regards,
    Rave

  • Hi, i have edited a clip in hd with final cut, now I need to export it in 2K format . anybody knows how i can do it in FCP?  in internet I found only few info about 2K format: no more than frame size.  nothing about codec or similar. thanks for any help.

    Hi, i have edited a clip in hd with final cut, now I need to export it in 2K format. anybody knows how i can do it in FCP?  in internet I found only few info about 2K format: no more than frame size.  nothing about codec or similar. thanks for any help.

    SoCal thanks for the attention,
    sorry for having wrote the question directly in the subject, but first i wrote it by text edit then copied it, but in the wrong place too.....
    coming to my question, timeline settings are:
    as it is a commercial promo that must be projected in a multiplex cinema, the 2K format is needed.
    I've heard about transcoding services, and they are very expensive. 
    so i'm looking if there is a way to do everything by fcp.
    the project will be delivered as SD DVD for archive pourposes and as a single file for the projection or eventually transconding.
    p.s.: sorry for my english, i'm from italy: had my last english lesson 35 years ago!

  • Find and Replace text and change font help needed.

    I am completely new to Scripting and I'm sure this is quite simple but I do not know where to start.
    I have a FM template that is populated with "raw" text from a database.
    Within the text are several characters (+, @, *, $, # and %).
    I need to replace these characters with symbols from a different font e.g.:
    Each instance of:
    "+" to be replaced with Wingdings 2 font - Lowercase t
    "@" to be replaced with Wingdings 2 font - Lowercase u
    "*"  to be replaced with Wingdings font - Uppercase E   etc.
    I would like to automate the process and believe a script would enable me to do this.
    I have tried looking on the forum, but can not find anything suitable to help me (or I'm looking in the wrong place).
    Any help would be greatly appreciated.
    Cheers
    Kev

    not really
    important is the Illustrator Text Object-model, which is not very easy to understand.
    And the Core JS String and regExp Objekts.
    Have a look at this:
    http://www.ogebab.de/home/skripte/text/replace
    The dialog is poor (because of compatibility) and it works simply on TextFrames.contents, i don't know if this is good i all cases.
    But i use it not very often so i don't want to rewrite it.
    Maybe it is a starting-point for you.
    But maybe it is more then you need.
    try this:
    //select a text
    var text = app.activeDocument.selection[0];
    var string = text.contents;
    string = string.replace(/ /g,"  ");
    text.contents= string;
    / /g is a regular expression
    .replace() is a method of the String Object
    both explained at
    https://developer.mozilla.org/en/JavaScript/Reference

  • Help - Need to save group text - story of daughter's life

    Hello and thank you in advance.  This may be a very dumb question, but I can't seem to find an easy solution in the research I have done.
    I have used a group text since the birth of my daughter to update family members on her life.  This group text is now basically the story of her life with pictures, things she has done, funny things she has said... I don't want to lose any of that.  However, my iPhone 4S 64G is now maxed on storage due to this group text.  I need to save this somehow, but don't know how to go about it.  I have backed up my phone many times, but now that I need to delete the text to gain storage capacity.  I don't want it to override the backup next time with the deletion.  I need to keep the history.
    Any suggestions on how I can go about that?
    I have purchased a program called DiskAid, but have not had time to see if it will suit my needs.
    Thank you,
    A mommy desperately in need of help!

    Hi Maggie,
    I would try the software decipher text message. It will let you save your text messages to your computer so that you can safely archive all the sms conversations between you and your family. 

Maybe you are looking for

  • Microphone too low on G780 in Windows 8

    When I used Skype, I heard complains, nobody could hear me. So I checked my microphone settings and they were set... to minimum (microphone 0, performance 0 dB) so I set it to maximum (microphone 100, performance +40 dB) and... with very weak results

  • Rotate external display

    How can i rotate my external display?  When i use the command-option key i get the option to rotate my i mac display but not my external display.

  • Show/ Hide Tables in SSRS based on Multiple Parameters

    Hi Is it possible to show/ hide multiple different tables based on a multivalued parameter?  I have 6 tables and I want 1 or 6 displayed dependent on what is selected from the multivalued parameter. When I add the IN operator and select multivalues,

  • Edge Animate responsive scaling problem

    Hello I am having a terrible time with the responsive scaling from Edge Animate. When I insert the html into a div in Dreamweaver the scaling works, however any divs below the animation get pushed down (when scaling the page) causing a large and unsi

  • [VLC] Immediate crash afters song playback is started...

    Hi guys, i update vlc to latest version VLC media player 2.0.0 Twoflower (revision 2.0.0-0-g421a4fc). But it simply works like s**t. Every time i start any song it plays for three seconds and VLC then crashes. Not sure of this is VLC or archlinux rel