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 8803045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:14:21+00:00 2026-06-14T01:14:21+00:00

I am having trouble determining how to split separate elements in a text file

  • 0

I am having trouble determining how to split separate elements in a text file in a usable way. My program is meant read in a text file to an arraylist, display the possible answers, ask for an answer and move on only when a correct answer is given. The trouble is, the text files must have different numbers of answers, so there is no numerical way to determine when a question is found in the text file and how many questions there are. Here is an example of a quiz text file:

How many licks does it take to get to the tootsie roll center of a tootsie pop?(QUESTION)

4(NUMERICAL VALUE ASSIGNED TO CORRECT ANSWER)

(POSSIBLE ANSWERS)

one

two

three

four

What is your name?

3

Arthur, King of the Britons

Sir Lancelot the Brave

Sir Robin the Not-Quite-So-Brave-As-Sir Lancelot

Who’s on first?

5

What

Why

Because

Who

I don’t know

I hate asking you guys a broad logic question as such, but I’m really stuck on this.
Here is my code:

import java.util.*;
import java.io.*;
public class JavaApplication8 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException{

    Scanner inScan = new Scanner(System.in);

    String file_name;
    System.out.print("What is the full file path name?\n>>");
    file_name = inScan.next();

    Scanner fScan = new Scanner(new File(file_name));
    ArrayList<String> Questions = new ArrayList();



    while (fScan.hasNextLine()) 
    {
        Questions.add(fScan.nextLine());
    }

    System.out.println(Questions.get(0));
    System.out.println(Questions.get(2));
    System.out.println(Questions.get(3));
    System.out.println(Questions.get(4));
    System.out.println(Questions.get(5));


    String guess;
    System.out.print("What is your answer?\n>>");
    guess = inScan.next();

    if (guess == Questions.get(1))
    {
        System.out.println("Correct");
    }

    else

        System.out.println("Incorrect");






}

**I did not code for the additional questions, only the first one.

  • 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-14T01:14:22+00:00Added an answer on June 14, 2026 at 1:14 am

    It appears the only instance of a question mark ? is when there is a question. Test each line from the file to see if there is a question mark in that line. If so, then that’s a new question/answer set.

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

Sidebar

Related Questions

I'm having trouble determining a way to parse a given text file. Here is
I'm having trouble determining the best way to read some input in for a
After my page loads my text disappears and I am having trouble determining why.
Having trouble determining if a file name conforms to a specific convention as follows.
I'm having trouble determining the file-type of an image I uploaded with Zend Framework.
I'm having trouble determining if it's possible, based on the amount of access I
I am having some trouble determining if two line segments are collinear because of
Having trouble with an .htaccess file on WAMP. Works on the live server, but
I'm having trouble determining what selector to use access the CSS properties. Here's my
I was having trouble determining what was cause my form to not submit when

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.