Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:51:59+00:00 2026-06-12T23:51:59+00:00

After someone inputs a text file, I have to make it so it will

  • 0

After someone inputs a text file, I have to make it so it will read the text file that the user inputted.

Using a switch statement, how do I make sure the first word and last word doesn’t have a specific character?

The first word should not have a single-quotation mark, double-quotation mark, a dollar sign, or a period.

The last word should not have a single-quotation mark, double-quotation mark, semi-colon, colon, period, comma, hyphen, exclamation point, or question mark remove it.

I am using hasNext in my while so that it prints each word on one line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:52:00+00:00Added an answer on June 12, 2026 at 11:52 pm

    Once you read in your first word you can call this function (passing in the first word as your parameter), it will return true if the word contains any illegal characters. You could then easily create another one to test your last word against.

    public boolean containsIllegalChar(String testWord){
    boolean containsIllegalChar = false;
    
    for(int count=0; count < testWord.length(); count++){
         char testChar = testWord.charAt(count);
         switch (testChar)
         {
         case ''': containsIllegalChar = true;
         break;
         case '"': containsIllegalChar = true;
         break;
         case '$': containsIllegalChar = true;
         break;
         case ' ': containsIllegalChar = true;
         break;
         default: break;
         }
    }
    return containsIllegalChar;
    }
    

    To test the last word you could use this structure

    String lastWord = "";
    while((holder = reader.read()) != -1){  
         lastWord = holder;
         //YOUR PROCESSING
    }
    boolean testLastWord = containsIllegalCharLastWord(lastWord);
    
    if(testLastWord){
    //Contains illegal char
    }
    else{
    //Does not contain
    }
    

    You could also replace containsIllegalChar function by testing your string against a nice regex. E.g

    boolean validWord = ("piz'za".matches("[^'\"$ ]+")) ? true : false;
    System.out.println(validWord);
    

    Result:

    false

    Hope this helps.
    Phil

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute a jquery script that will fade a <label for='username'> after
I have a form in a php page with a lot of text inputs
I have the following jQuery functions: <script type=text/javascript> $(function() { // setTimeout() function will
I have an ASP.NET MVC application and I'm using CKEditor for text entry. I
(define bootstrap-c-code (define (from-file file-name) (let* ((ip (open-input-file file-name)) (res (read-text-file-from-input-port ip))) (close-input-port ip)
Can someone help me make the original code from HTML5 Boilerplate Initializser, have the
I am writing a Java program that inputs a test file, performs some modifications
So, I'm looking through a java library (JScience) after someone here thoughfully pointed me
After a short debate with someone about exception handling in Python - sparked by
I'm working with someone who's looking to get back into programming after several years

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.