Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.HashSet;
import java.util.Set;

public class Main {
    private static Set<String> getRedSet(Set<Integer> numSet) {
        Set<String> redSet = new HashSet<String>();

        // add single Num
        Set<String> headSet = getHeadSet(numSet);
        for (Integer singleNum : numSet) {
            if (singleNum == 0)
                continue;
            redSet.add("" + singleNum);
        }

        for (String head : headSet) {
            for (Integer tail : numSet) {
                if (head.equals("3") && tail > 3)
                    continue;
                redSet.add(head + tail);
            }
        }

        return redSet;
    }

    private static Set<String> getHeadSet(Set<Integer> numSet) {
        Set<String> headSet = new HashSet<String>();
        for (Integer i : numSet) {
            if (i < 4 && i > 0) {
                headSet.add("" + i);
            }
        }
        return headSet;
    }
}