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

  • Home
  • SEARCH
  • 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 7764527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:56:06+00:00 2026-06-01T14:56:06+00:00

I wanted to write a short programm, which replaces the Counting of a String.

  • 0

I wanted to write a short programm, which replaces the Counting of a String. So I would like to start the String with 0 insted of 1. And Because it is a long String i dont want to change it all by my own. So the String (in this example) is: String LINE:

  1. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
  2. magna aliquyam erat, sed diam voluptua.
  3. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
  4. dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
  5. magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
  6. no sea takimata sanctus est Lorem ipsum dolor sit amet.

And I want the String to start the counting with 0. and go on wit 1.2.3….(0,1,2,3,4…)

public static void main(String[] args) {
    for (int counter = 1; counter <= 300; counter++) {

        int NormCounter =1;
        int ReplaceCounter = 0;

        String NormCounterS  = (new Integer(NormCounter)).toString() + ".";

        String ReplaceCounterS = (new Integer(ReplaceCounter)).toString() + ".";
        Line = Line.replace(NormCounterS , ReplaceCounterS);
        ++ReplaceCounter;

        ++NormCounter;
    }

    System.out.println(Line);
}

it just changes the first “1.” into “0.”… So its 0,2,3,4… But i want the counting to go 0,1,2,3,4

  • 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-01T14:56:08+00:00Added an answer on June 1, 2026 at 2:56 pm

    Even though you increment your counters, you re-set the counters to 1 and 0 every time the loop iterates. You should probably move this code:

    int NormCounter = 1;
    int ReplaceCounter = 0;
    

    To outside the for-loop:

    public static void main(String[] args) {
    
        int NormCounter = 1;
        int ReplaceCounter = 0;
    
        for (int counter = 1; counter <= 300; counter++) {
            String NormCounterS  = NormCounter + ".";
            String ReplaceCounterS = ReplaceCounter + ".";
    
            Line = Line.replace(NormCounterS, ReplaceCounterS);
    
            ++ReplaceCounter;
            ++NormCounter;
        }
    
        System.out.println(Line);
    }
    

    Also notice how String NormCounterS = (new Integer(NormCounter)).toString() + "."; can be rewritten more simply String NormCounterS = NormCounter + ".";. (The end result is the same).

    See Laky’s comment for an additional bug fix to this method.

    Also just a small plug for Java coding conventions: it is standard to name Java variables with a lower case starting letter. E.g. use normCounter instead of NormCounter.

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

Sidebar

Related Questions

I wanted to write a short programm, which replaces the Counting of a String.
I wanted to write a Custom Control that would show a family tree... so
I wanted to write an extension-method that would work on dictionaries whose values were
I wanted to write something basic in assembly under Windows. I'm using NASM, but
I wanted to write a regex to count the number of spaces/tabs/newline in a
Just wanted to write some recursion but can't check if the child is in
I wanted to write following query through codeigniter's db helper class, guide me plz
I wanted to write a method with an argument that defaults to a member
I wanted to write a program that test if two files are duplicates (have
I wanted to write kannada alphabet/word on top of the button instead of english.

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.