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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:29:02+00:00 2026-05-26T16:29:02+00:00

At my university we regurly get programming assignments that (at least for now) usually

  • 0

At my university we regurly get programming assignments that (at least for now) usually deal with console programming. When I create my programs in Netbeans and compile and run from there, everything works as expected… However, when manually compiling using javac filename.java and running using java filename, i get wierd formatting errors when printing out lines… (System.out.println and System.out.printf)

Take this as an example. I’m printing out the contents of a table which when run in Netbeans looks like this:

Hybel Leietager      Saldo
--------------------------
1A    Ole Johan     6000
1B    Erik Smith    12000
1C    TOM HYBEL     0
1D    Alan Turen    9000
1E    Tim Verner    33000
1F    Anders Tanen  4999
2A    Torvald Linus 9000
2B    Rikard Stall  5001
2C    Bill Weitz    10000
2D    Steve Job     15000
2E    Steve Woz     123
2F    Denis Rich    2400
3A    James Goblin  88000
3B    Mark Sukker   456000
3C    Karl Bagasje  6000
3D    TOM HYBEL     0
3E    Ada Love      250
3F    Don Knut      55000

Periode: 9/2011
Total fortjeneste: 1400500

However, when manually compiling and running i get this:

Hybel Leietager      Saldo
--------------------------
    6000 Johan
   12000k Smith
    0TOM HYBEL
   9000an Turen
   33000 Verner
 4999Anders Tanen
9000 Torvald Linus
 5001Rikard Stall
   10000l Weitz
    15000e Job
    123eve Woz
   2400nis Rich
 88000ames Goblin
  456000k Sukker
 6000Karl Bagasje
    0TOM HYBEL
     250 Love
     55000nut

Periode: 9/2011
Total fortjeneste: 1400500

I don’t understand, the function printing this out is a simple for-loop with System.out.println or printf… Anyone understand why this happens?

Here is the code, a bit difficult to understand as it’s written in norwegian (i know, bad practise, it should all be english… but we’re required to do it in the class, bad teachers, BAD!)

Basically, lengdenAvLengsteNavn() finds the longest name (listed under “Leietager”). genererOversiktTop() creates the header line, with required spacing (depending on the longest name). The header line is what reads “Hybel Leietager…..Saldo”. horizontalSkille() prints out the horizontal devider (“——–….”), and hybelOversiktLinje() actually prints the line representing a hybel (condo) with correct spacing… As you can see, no tabs or /r’s are used…

private void skrivOversikt () {
    System.out.println("*** Hybel Oversikt *** \n");
    String oversiktTop = genererOversiktTop();
    System.out.println(oversiktTop);
    System.out.println(horizontalSkille (oversiktTop.length()));

    for(int i = 0; i < etasjer.length; i++) {
        Etasje etasje = etasjer[i];
        for(int j = 0; j < etasje.hybler().length; j++) {
            Hybel hybel = etasje.hybler()[j];
            System.out.print(hybelOversiktsLinje (oversiktTop, hybel) + "\n");
        }
    }

    System.out.println();
    System.out.println("Periode: " + innevaerendeMaaned + "/" + innevaerendeAar);
    System.out.println("Total fortjeneste: " + totalFortjeneste);
} //Skriver ut en oversikt over alle hybler, leietagere og deres saldo

private String genererOversiktTop () {
    String oversiktsTop = "Hybel Leietager";
    int leietagerSaldoSkille = lengdenAvLengsteNavn() - "Leietager".length();

    for (int i = 0; i < leietagerSaldoSkille; i++) {
        oversiktsTop += " ";
    }

    return oversiktsTop + " Saldo";
}

private String horizontalSkille (int lengde) {
    String skille = "";

    for (int i = 0; i < lengde; i++) {
        skille += "-";
    }

    return skille;
}

private String hybelOversiktsLinje (String oversiktsTop, Hybel hybel) {
    int leietagerIndex = oversiktsTop.indexOf("Leietager");
    int saldoIndex = oversiktsTop.indexOf("Saldo");
    String linje = hybel.romNavn();

    while (linje.length() < leietagerIndex) {
        linje += " ";
    }

    linje += hybel.leietagerNavn();

    while (linje.length() < saldoIndex) {
        linje += " ";
    }

    return linje + hybel.saldo();
}

private int lengdenAvLengsteNavn () {
    int lengsteLengde = 0;

    for (int i = 0; i < etasjer.length; i++) {
        for (int j = 0; j < etasjer[i].hybler().length; j++) {
            Hybel hybel = etasjer[i].hybler()[j];

            if (hybel.leietagerNavn().length() > lengsteLengde)
                lengsteLengde = hybel.leietagerNavn().length();
        }
    }

    return lengsteLengde;
}
  • 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-26T16:29:02+00:00Added an answer on May 26, 2026 at 4:29 pm

    You are printing '\r' character after the name. This character is interpreted differently on those two terminals.

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

Sidebar

Related Questions

For my university I have to create an application that for the User Interfaces
For a university assignment in Java the specification requires that Code Listings: in 10-point
When I went to University, teachers used to say that in good structured application
My university is hosting a Programming Competition, and have decided to support Turbo C
I am a university student working on a research project that involves migrating a
Background : For an university project I have to use PHP5 to create a
I've got a university project to create a site using a framework given to
For a University assignment I'm building a class structure that includes, in part, several
For my university I (and three others), are searching for a project that utilizes
For my university project I am creating a neural network that can classify the

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.