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

  • SEARCH
  • Home
  • 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 6992095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:35:25+00:00 2026-05-27T19:35:25+00:00

Hi I’m writing my first Java app and I’ve got a few Testcases (*.tc

  • 0

Hi I’m writing my first Java app and I’ve got a few Testcases (*.tc files) I want to direct to the app via this script:

for f in `ls *.tc`; do
  echo "Current Testcase: $f"
  x=${f%.*}
  java Main < $x.tc > $x.out

  if diff "$x.out" "$x.should"; then
    echo "passed testcase $f"
    let PASSED=PASSED+1
  else
    echo "failed testcase $f"
    let FAILED=FAILED+1
 fi
done

The Problem is I can’t quite figure out why as soon as the tc file contains more than one line the app goes nuts. For example: quit.tc contains

quit

and works just like when I manually enter “quit”, therfore the testcase passes.
However when I write another tc: quit2.tc which contains

lala
test
quit

The app quits after the first command (because the readString function seems to return null afterwards).
Here is the function responsible for reading:

public String readString(){

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String answer = null;

try {
  answer = br.readLine();
  return answer;
}
catch(IOException ioe) {
  System.out.println("IO Error");
}
return answer;
}   

I dont know why or when this function returns null when I redirect to the app, which seems to be the problem. Can you help out so I can get the tc script working? thx

  • 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-05-27T19:35:26+00:00Added an answer on May 27, 2026 at 7:35 pm

    If you’re new to java, and you still shape your style and way of doing things, I will recommend you 2 tips:

    1) use Scanner to read your input. Using nextLine() method of the Scanner object is probably what you’re looking for.

    2) design your code, so that it’s testable via JUnit.

    Still, in your readString() method, remove the return answer; from the try block.

    UPDATE: try to implement the following in your function:

    a) while the scanner instance hasNextLine() is true ->

    b) call scanner instance nextLine() method ->

    c) parse the line, and see if it equals ‘quit’ ->

    d) implement the corresponding logical if cases.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.