MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

public class MainClass {
    public static void main(String args[]) {
        String firstString = "This sentence ends in 5 stars *****";
        String secondString = "1, 2, 3, 4, 5, 6, 7, 8";

        System.out.printf("Original String 1: %s\n", firstString);

        // replace first three digits with 'digit'     
        for (int i = 0; i < 3; i++)
            secondString = secondString.replaceFirst("\\d", "digit");

        System.out.printf("First 3 digits replaced by \"digit\" : %s\n", secondString);

    }
}