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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:48:51+00:00 2026-05-26T20:48:51+00:00

First, this is the first programming class I’ve taken, so I apologize if this

  • 0

First, this is the first programming class I’ve taken, so I apologize if this is a pretty simple problem. for a homework assignment, we have to write a program which scans a text file, prompts the user for words identified by < >, and then writes the result to another text file.

The problem I’m having is that the output file is all written on a single line, instead of preserving the line breaks from the input file.

For example:

The input

looks like

this text.

the output looks like this text.

This is the code I have in the relevant method.

public static void createMadLib(Scanner console) throws FileNotFoundException {
    Scanner input = getInput(console);
    System.out.print("Output file name: ");     
    PrintStream out = new PrintStream(new File(console.nextLine()));
    System.out.println();

    String text = input.next();
            while (input.hasNext()){


                    if (text.startsWith("<")){
                        text = text.substring(1, text.length()-1);
                        text = text.replace("-"," ");
                        if ((text.startsWith("a"))||(text.startsWith("e"))||(text.startsWith("i"))||(text.startsWith("o"))||(text.startsWith("u"))){                        
                            System.out.print ("Please type an " + text + ": ");
                            text = (console.nextLine());
                        }else {
                            System.out.print ("Please type a " + text + ": ");
                            text = (console.nextLine());
                        }
                    }
                    out.print(text + " "); 

                    text = input.next();

            }//ends while loop  
    out.print(text);
    prompt(console);
    }

I apologize for any formatting faux pas, again, this is my first programming class.

Thanks for your help

  • 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-26T20:48:52+00:00Added an answer on May 26, 2026 at 8:48 pm

    Instead of using out.print, you may want to use out.println, which does the same thing, but appends a newline character to the end of the line. You can also manually concatenate the newline character (\n) where you wish to insert linebreaks.

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

Sidebar

Related Questions

For a programming class I am creating a blackjack program for the first homework
I have to write a program for my C programming class that takes a
First of all this is all just concept, I have no actual programming done
First of all I have to admit that my programming skills are pretty limited
Disclaimer: this question is directly related to my programming homework. My C++ assignment consists
This is my first attempt at java problem I have been given as part
First, let me state that this is a programming question (and thus does not
This question might not seem programming related at first, but let me explain. I'm
I am taking my first steps programming in Lua and get this error when
I'll be the first to admit that this is cut and past programming. I've

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.