0

I am attempting to write a program that creates a table based on parameters given by the user that describe a graph. I am merely a beginner in Java and am just starting out, so if I am using inefficient methods then that might be the reason for that. The problem that I am encountering while writing the code is that there seems to be a strange occurrence when I run the program that causes one row to have a different spacing between columns than other rows. This is extremely infuriating and I would love to have a solution to this. Again, I am an extreme beginner and am still wrapping my mind around writing mid sized programs. T

Scanner input = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);
Scanner input3 = new Scanner(System.in);
Scanner input4 = new Scanner(System.in);
Scanner input5 = new Scanner(System.in);

    double xjumps;
    double yjumps;
    double start;
    double length;
    double intercept;

    System.out.printf("Please input the length of your table: ");
    length = input.nextDouble();

    System.out.printf("\n");
    System.out.printf("Please input the x-axis incrementation: ");
    xjumps = input2.nextDouble();

    System.out.printf("\n");
    System.out.printf("Please input the y-axis incrementation: ");
    yjumps = input3.nextDouble();

    System.out.printf("\n");
    System.out.printf("When do you want the table to start: ");
    start = input4.nextDouble();

    System.out.printf("\n");
    System.out.printf("Please input the y intercept: ");
    intercept = input5.nextDouble();


    double x = start;
    double y = (((start/xjumps) * yjumps) + intercept);

    System.out.printf("\n");
    System.out.println("X\t\t\tY");
    System.out.println(x + "\t\t" + y);
    for(double z = -1;z <= length;z++){
        x += xjumps;
        y += yjumps;
        System.out.println(x + "\t\t" + y);

    }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Please provide the output of the program as well. You are using adjacent tabs, so if one of your cell contents crosses a tab boundary, the alignment will fail. Perhaps instead you should [construct](https://stackoverflow.com/questions/18672643/how-to-print-a-table-of-information-in-java) the row as a string and write the columns at the specified positions. – Dominic Cerisano Feb 02 '19 at 21:59
  • Use `String.format` (or one of the variants), for [example](https://stackoverflow.com/questions/2745206/output-in-a-table-format-in-javas-system-out), [example](https://stackoverflow.com/questions/26229140/writing-data-to-text-file-in-table-format/26229246#26229246), [example](https://stackoverflow.com/questions/28802139/how-to-align-my-results-to-look-like-columns/28802198#28802198) – MadProgrammer Feb 02 '19 at 22:05

0 Answers0