Jump to content
Sign in to follow this  
Guest olyvaha

Whitespace Hw

Recommended Posts

Guest olyvaha

no idea how to even begin, its been along time since i touched java and this is like trying to climb a glass wall...some pointers, someone said something about using Character.isWhitespace() but java has become foreign to methanks for any help you can offer

public class Lex{private String s; // input stringpublic String[] tokens = new String[20]; //scanned tokensprivate final char nullChar = '\u0000';private int currentCharLocation = 0;private char c='1'; //character under examinationpublic Lex(String s){this.s = s;scan();}private void scan(){String token="";int currentToken=0; //count of tokensc = getChar()skip white space at start of linewhile (c /= nullchar){if not whitespace{append c to token and get next character}else //found white space, add token to list{add token to token listadvance token counterclear tokenskip whitespace}}//if}//whileif (token != "") //add last token to listtokens[currentToken]=token;}private char getChar(){return a character from the stringif end of string return null character}private void skipWhitespace(){skip spaces and tabsmake use of getChar}public static void main(String[] args){//add more test casesLex l = new Lex(" aaa bbbb ccccc ddddd ");for(int i = 0; i < l.tokens.length; i++){System.out.println(i + "\t" + l.tokens[i]);}}// main}//Lex

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...