Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {

    public static void main(String[] args) {
        String string = "java 2s.com java";
        int length = string.length();
        if (length < 2) {
            System.out.println(string);
            return;
        }

        System.out.print(string.charAt(0));
        for (int i = 1; i < length; i++) {
            if (string.charAt(i) != string.charAt(i - 1)) {
                System.out.print(string.charAt(i));
            }
        }
    }
}