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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:18:22+00:00 2026-05-22T20:18:22+00:00

We are suppose to write a calendar for a project. I’m using an array

  • 0

We are suppose to write a calendar for a project. I’m using an array to keep track of how many days in a month there are and get a long list of numbers equal to the value of that array index. I then populate a String using a loop until that loop is equal to the value of that index.

The string is loaded into a textshape, which was given by our professor. I want to display each text line that is generated by substring() into one separate line. I tried to start at a higher index (30, 59) but it returns an error b/c my initial string isn’t long enough.

So what i want to do is make that long list of numbers into separate lines. A classmate of mine said to use substring. It does work, generally but will only give me the first line.

this is the method to generate my string.

    public String toString() {

    monthPlusOne = month + 1;
    for (int i = 0; i < monthsArray[monthPlusOne]; i++) {
        String temp;
        //temp = "" + i;
        subLine = subLine + (i+1) + " ";

        }
    totalLine = subLine;


    String output = monthText + " " + year + " \n "
            + "Su Mo Tu We Th Fr Sa\n" + totalLine;

    return output;
}

it feeds into this this method which origanlly had the calender in just number form with manual “\n” inserted into it. The string would split when it found those “\n”

public static void displayCalendar() {
    String s = calendar.toString().substring(30);

    // extract all of the lines in s
    // split s on \n
    String[] lines = s.split("\n");
    int index = 0;
    for (String line : lines) {
        t[index].setText(line);
        index++;
    }
}
  • 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-22T20:18:22+00:00Added an answer on May 22, 2026 at 8:18 pm

    Get rid of all those substring() and split() calls and add

    if((i + 1) % 7 == 0)subLine += "\n";
    

    inside the loop in toString().

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

Sidebar

Related Questions

Would it suppose any difference regarding overhead to write an import loading all the
Suppose I am writing an application in C++ and C#. I want to write
Suppose a long-running process writes to a log file. Suppose that log file is
Java is supposed to be write once, run anywhere and it really can be,
Suppose someone (other than me) writes the following code and compiles it into an
Suppose you have the following string: white sand, tall waves, warm sun It's easy
I need to write a java script. This is supposed to validate if the
Suppose your git history looks like this: 1 2 3 4 5 1–5 are
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
I am using a 3rd-party rotator object, which is providing a smooth, random rotation

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.