Facebook Google Plus YouTube

URI Problem (Sequence IJ 4) 1098:
Sequence IJ 4 is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.text.DecimalFormat;

/**
 * @E-mail : md.parvez28@gmail.com
 * @Date : Oct 16, 2016
 * @Time : 11:28:50 PM
 */
public class Uri1098 {

    public static void main(String[] args) {
        for (double i = 0; i <= 2; i += 0.2) {
            System.out.println("I=" + go(toDouble(i)) + " J=" + go(toDouble(i + 1)));
            System.out.println("I=" + go(toDouble(i)) + " J=" + go(toDouble(i + 2)));
            System.out.println("I=" + go(toDouble(i)) + " J=" + go(toDouble(i + 3)));
        }
    }

    private static String go(double d) {
        if (d == (int) d) {
            return "" + (int) d;
        } else {
            return "" + d;
        }
    }

    private static double toDouble(double x) {
        DecimalFormat format = new DecimalFormat("#0.0");
        return Double.valueOf(format.format(x));
    }
}

Leave a Reply

%d bloggers like this: