Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

java - How to wrap text the numbers?

The numbers are from a text file being scanned in my Java code and I was wondering if it's possible to "wrap text" the peak numbers so it's easier to view them when I run them? The examples is down below with the code under.

This is what it looks like:

PEAKS: 98535 98662 98517 98649 98621 98563 98640 98576 98655 98539 98654 98588 98594 98659 98598 98613 98635 98616 98634 98509 98667 98613 98647 98647 98485 98529 98658 98661 98629 98665 98600 98616 98597 98647 98548 98488 98654 98492 98623 98619 98577 98635 98591 98563 98573 98503 98559 98561 98627 98579 98491 98638 98573 98643 98647 98561 98642 98604 98591 98649 98667 98612 98648 98558 98638 98665 98559 98491 98573 98637 98531 98566 98580 98660 98597 98538 98556 98588 98534 98506 98661 98622 98630 98491 98511 98602 98582 98599 98667 98609 98648 98605 98501 98569 98484 98518 98560 98587 98482 98492 98633 98625 98645 98636 98528 98514 98490 98520 98533 98549 98572 98576 98525 98533 98592 98628 98483 98616 98599 98643 98530 98490 98490 98518 98565 98637 98510 98658 98554 98569 98510 98637 98552 98658 98503 98556 98485 98493 98608 98657 98648 98502 98543 98606 98651 98632 98630 98582 98583 98601 98508 98588 98661 98627 98487 98586 98515 98535 98516 98608 98574 98616 98580 98497 98528 98657 98618 98550 98513 98592 98483 98637 98537 98565 98592 98556 98539 98538 98657 98654 98537 98594 98486 98538 98666 98544 98604 98637 98542 98561 98582 98568 98545 98532 98584 98614 98611 98538 98590 98570 98610 98644 98519 98513 98612 98641 98664 98565 98579 98623 98633 98509 98495 98613 98662 98662 98567 98642 98516 98627 98643 98498 98553 98527 98539 98647 98550 98485 98527 98599 98663 98593 98533 98634 98554 98656 98597 98512 98636 98653 98620 98634 98600 98622 98597 98565 98490 98583 98547 98556 98529 98632 98579 98597 98572 98655 98628 98592 98520 98540 98654 98647 98662 98619 98645 98518 98652 98596 98590 98623 98652 98514 98623 98517 98608 98547 98638 98632 98651 98611 98494 98590 98628 98620 98614 98621 98634 98609 98605 98645 98665 98642 98646 98622 98663 98635 98523 98586 98654 98555 98641 98629 98648 98650 98662 98647 98540 98603 98650 98515 98513 98666 98665 98609 98629 98586 98504 98574 98641 98607 98607 98557

How I actually want it to look like

PEAKS: 98535 98662 98517 98649 98621 98563 98640 98576 98655 98539 98654 98588 98594 98659 98598 98613
98635 98616 98634 98509 98667 98613 98647 98647 98485 98529 98658 98661 98629 98665 98600 98616 98597
98647 98548 98488 98654 98492 98623 98619 98577 98635 98591 98563 98573 98503 98559 98561 98627 98579
98491 98638 98573 98643 98647 98561 98642 98604 98591 98649 98667 98612 98648 98558 98638 98665 98559
98491 98573 98637 98531 98566 98580 98660 98597 98538 98556 98588 98534 98506 98661 98622 98630 98491
98511 98602 98582 98599 98667 98609 98648 98605 98501 98569 98484 98518 98560 98587 98482 98492 98633
98625 98645 98636 98528 98514 98490 98520 98533 98549 98572 98576 98525 98533 98592 98628 98483 98616
98599 98643 98530 98490 98490 98518 98565 98637 98510 98658 98554 98569 98510 98637 98552 98658 98503 
98556 98485 98493 98608 98657 98648 98502 98543 98606 98651 98632 98630 98582 98583 98601 98508 98588
98661 98627 98487 98586 98515 98535 98516 98608 98574 98616 98580 98497 98528 98657 98618 98550 98513
98592 98483 98637 98537 98565 98592 98556 98539 98538 98657 98654 98537 98594 98486 98538 98666 98544
98604 98637 98542 98561 98582 98568 98545 98532 98584 98614 98611 98538 98590 98570 98610 98644 98519
98513 98612 98641 98664 98565 98579 98623 98633 98509 98495 98613 98662 98662 98567 98642 98516 98627
98643 98498 98553 98527 98539 98647 98550 98485 98527 98599 98663 98593 98533 98634 98554 98656 98597
98512 98636 98653 98620 98634 98600 98622 98597 98565 98490 98583 98547 98556 98529 98632 98579 98597
98572 98655 98628 98592 98520 98540 98654 98647 98662 98619 98645 98518 98652 98596 98590 98623 98652
98514 98623 98517 98608 98547 98638 98632 98651 98611 98494 98590 98628 98620 98614 98621 98634 98609
98605 98645 98665 98642 98646 98622 98663 98635 98523 98586 98654 98555 98641 98629 98648 98650 98662
98647 98540 98603 98650 98515 98513 98666 98665 98609 98629 98586 98504 98574 98641 98607 98607 98557 

Code

    private void numPeaks() {
        peakX = new int[100000];
        peakY = new int[100000];
        peakNum = 0;
        for (int i = 0; i < numRow; i++) {
            for (int j = 0; j < numCol; j++) {
                int r1 = i - exRad;
                int r2 = i + exRad;
                int c1 = j - exRad;
                int c2 = j + exRad;
                if (r1 >= 0 && r2 <= numRow-1 && c1 >= 0 && c2 <= numCol-1) {
                    boolean loop = true;
                    for (int r = r1; r <= r2; r++) {
                        for (int c = c1; c <= c2; c++) {
                            if (i != r && j != c && grid[i][j] <= grid[r][c]) {
                                loop = false;
                                break;
                            }
                        }
                    }
                    if (loop && grid[i][j] >= 98480) {
                        peakX[peakNum] = i;
                        peakY[peakNum] = j;
                        peakNum++;
                    }
                }
            }
        }
        System.out.print("PEAKS: ");
        for (int i = 0; i < peakNum; i++) {
            System.out.print(grid[peakX[i]][peakY[i]] + " ");
        }
        System.out.println();
    }
question from:https://stackoverflow.com/questions/65866104/how-to-wrap-text-the-numbers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could alter your display section so it prints a new line when a certain number of peaks been already printed on the same line; Something like:

 int peaksOnSameLine = 0;
 int maxPeaksPerLine = 20; // for example, just 20 per line

 System.out.print("PEAKS: ");
 for (int i = 0; i < peakNum; i++) 
 {  
     peaksOnSameLine++;
     System.out.print(grid[peakX[i]][peakY[i]] + " ");
     if (peaksOnSameLine == maxPeaksPerLine)
     {
        System.out.println();
        peaksOnSameLine = 0;
     }
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...