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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:13:58+00:00 2026-06-13T23:13:58+00:00

code is working fine, I’m just curious as to how I can prevent the

  • 0

code is working fine, I’m just curious as to how I can prevent the char 0D from printing at the end of my text file if at all possible.
Thank you.
here’s the code if it helps. sorry if it’s mediocre, still learning java.

           import java.util.*;  
   import java.io.*;

   public class Driver{
      String inputFile, input;
      Scanner kb = new Scanner(System.in);
      PrintWriter output = new PrintWriter(System.out);
      File file; 
      BST tree = new BST();
      Trie trie = new Trie();


      public static void main(String[] args){
         Driver driver = new Driver();
         boolean done = false;  

         driver.initialDataFromFile();
         while (!done){      
            done = driver.menu(true);   
         }
      }

      public void initialDataFromFile() {
         System.out.println("Welcome to Project0");
         System.out.println("What is the name of the input file?");
         System.out.print("> ");
         inputFile = kb.nextLine(); 
         File file = new File(inputFile);

         try{
            Scanner scanner = new Scanner(file);

            while(scanner.hasNextLine()){
               String in = scanner.nextLine();
               tree.insert(in);
               trie.insert(in);
            }
            System.out.println("Finished reading the file");

         }
            catch(FileNotFoundException e){
               System.out.println("File does not exist");
               System.exit(1);
            }
      }

      public boolean menu(boolean done){      
         System.out.print("Please enter your command\r>");
         input = kb.next();
         File file = new File(inputFile);
         PrintWriter output = null;// = new PrintWriter(inputFile);

         if(input.toLowerCase().equals("quit")){
            System.out.println("Quitting");
            System.out.println("Writing updated info to " + inputFile);     
            try{
               output =  new PrintWriter(file);
             //   String str = "";
//                str += tree.toString();
               output.println(tree.toString());  

               output.close();

            }
               catch(IOException e){
                  System.out.print("error");}
            System.out.println("Goodbye");    
            return true;       
         }

         else if(input.toLowerCase().equals("insert")){
            input = kb.next();
            tree.insert(input);
            trie.insert(input);
            System.out.println();
            return false;
         }
         else if(input.toLowerCase().equals("delete")){
            input = kb.next();
            tree.delete(input);
            trie.delete(input);
            System.out.println();  
            return false;
         }
         else if(input.toLowerCase().equals("find")){
            input = kb.next();
            tree.find(input);
            trie.find(input);
            System.out.println();
            return false;
         }
         else if(input.toLowerCase().equals("print")){
            tree.print();
            trie.print();
            System.out.println();
            return false;
         }
         else{
            System.out.println("Not A Valid Choice");
            System.out.println();
            return false;
         }
      }
   }
  • 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-13T23:13:58+00:00Added an answer on June 13, 2026 at 11:13 pm
    printWriter.println("...")
    

    will use OS dependant line.separator property to determine line separator sequence:

    These methods use the platform’s own notion of line separator rather than the newline character.

    It happens to be \r (?) on your computer (OD) (from JavaDoc of PrintWriter.println()):

    The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

    Just use plain print() and attach whichever character you want:

    printWriter.print("...\n")
    

    …or override the line.separator property.

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

Sidebar

Related Questions

I've got Code Contracts working fine from inside Visual Studio 2010, but I can't
This line of code is working fine for Firefox $(#<%=txt1.ClientID%>).text() but not for IE8
This is my code.Its working fine on firefox <script language=JavaScripttype=text/javascript> window.onload=function createDiv() { var
I have the code here working fine except that all the non-power of 2
this code was working fine till this morning, can anyone spot my mistake? probably
I’m trying to issue web requests asynchronously. I have my code working fine except
My code is working fine without any errors when running in Netbeans. If I
So basically this code was working fine before. I had some computer issues and
the below code is working fine if the user enters the USN number that
For single output types my code is working fine but I couldn't get how

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.