1.
/**
* Angewandte Mathematik, SS11
* Problem: 11715 - Car
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=117&problem=2762
*
* @author Gent Selmanaj
* @author Marco Schuster
* @author Chris Westerfield
* @version 1.0, 2011-04-19
*
* Method :
* Status : Accepted (#8760348)
* Runtime: 0.128
*/
import java.util.Locale;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int caseNo = 0;
while (sc.hasNext()) {
caseNo++;
String line = sc.nextLine();
if (line.equals("0"))
break;
String[] l = line.split(" ");
Double[] vals = new Double[3];
vals[0] = Double.parseDouble(l[1]);
vals[1] = Double.parseDouble(l[2]);
vals[2] = Double.parseDouble(l[3]);
// u: current speed
// a: constant acceleration in m/sē
// t: elapsed time
// v: new speed after t is elapsed
// s: displacement after t is elapsed
switch (Integer.parseInt(l[0])) {
case 1: // gegeben: u v t/ gesucht: s a
{
Double a = (vals[1] - vals[0]) / vals[2];
Double s = (a * Math.pow(vals[2], 2)) / 2.0 + vals[0] * vals[2];

System.out.printf(Locale.ENGLISH, "Case %d: %.3f %.3f\n",
caseNo, s, a);
}
break;

case 2: // gegeben: u v a/ gesucht: s t
{
Double t = (vals[1] - vals[0]) / vals[2];
Double s = (vals[2] * Math.pow(t, 2)) / 2.0 + vals[0] * t;

System.out.printf(Locale.ENGLISH, "Case %d: %.3f %.3f\n",
caseNo, s, t);
}
break;
case 3: // gegeben: u a s/ gesucht: v t
{
Double D = Math.pow(vals[0], 2) - 4 * 0.5 * vals[1]
* (-vals[2]);
Double t1 = (-vals[0] + Math.sqrt(D)) / vals[1];
Double t2 = (-vals[0] - Math.sqrt(D)) / vals[1];
Double t = (t1 < 0) ? t2 : t1;
Double v = vals[1] * t + vals[0];
System.out.printf(Locale.ENGLISH, "Case %d: %.3f %.3f\n",
caseNo, v, t);
}
break;
case 4: // gegeben: v a s/ gesucht: u t
{
Double u = Math.sqrt(Math.pow(vals[0], 2) - 2 * vals[1]
* vals[2]);
Double t = (vals[0] - u) / vals[1];
System.out.printf(Locale.ENGLISH, "Case %d: %.3f %.3f\n",
caseNo, u, t);
}
break;
}
}
}
}

2.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

/**
* Angewandte Mathematik, SS11
* Problem: 11715- Car
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2762
*
* @author Benjamin Vogt
* @author Sebastian Stumpf
* @version 1.0, 05/05/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.140
*/

public class Main
{
public static void main(String[] args)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer;
int myCase;
double one;
double two;
double three;
String resultOne;
String resultTwo;
int counter = 1;
double temp;
DecimalFormat f = new DecimalFormat("#0.000");
try
{
tokenizer = new StringTokenizer(reader.readLine());
myCase = Integer.valueOf(tokenizer.nextToken());
one = Double.valueOf(tokenizer.nextToken());
two = Double.valueOf(tokenizer.nextToken());
three = Double.valueOf(tokenizer.nextToken());

/*Presentation Error
* => mit formatter auf 3 nachkommastellen
* => StringBuilder.append(restultOne)
*
*/

while(true)
{
if(myCase == 1)
{
temp = (two-one)/three;
resultOne = f.format(temp);
three = (two*two-one*one)/temp/2;
resultTwo =f.format(three);
resultOne = resultOne.replaceAll(",",".");
resultTwo = resultTwo.replaceAll(",",".");
System.out.printf("Case "+counter+": "+resultTwo+" "+resultOne+"\n");
}

else if(myCase == 2)
{
temp = (two-one)/three;
resultOne = f.format(temp);
two = three*temp*temp/2+(one*temp);
resultTwo = f.format(two);
resultOne = resultOne.replaceAll(",",".");
resultTwo = resultTwo.replaceAll(",",".");
System.out.printf("Case "+counter+": "+resultTwo+" "+resultOne+"\n");
}

else if(myCase == 3)
{
temp = Math.sqrt(one*one+2*two*three);
resultOne = f.format(temp);
three = (temp-one)/two;
resultTwo = f.format(three);
resultOne = resultOne.replaceAll(",",".");
resultTwo = resultTwo.replaceAll(",",".");
System.out.printf("Case "+counter+": "+resultOne+" "+resultTwo+"\n");
}

else if(myCase == 4)
{
temp = Math.sqrt(one*one-2*two*three);
resultOne = f.format(temp);
three = (one-temp)/two;
resultTwo = f.format(three);
resultOne = resultOne.replaceAll(",",".");
resultTwo = resultTwo.replaceAll(",",".");
System.out.printf("Case "+counter+": "+resultOne+" "+resultTwo+"\n");
}

tokenizer = new StringTokenizer(reader.readLine());
myCase = Integer.valueOf(tokenizer.nextToken());
one = Double.valueOf(tokenizer.nextToken());
if(myCase == 0)
{
System.exit(0);
}
two = Double.valueOf(tokenizer.nextToken());
three = Double.valueOf(tokenizer.nextToken());
counter++;
}
}
catch(Exception e){}
}
}


-------------------------------------------------------


1.

/**
 *
 * Problem #11715 - Car
 * http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2762


 *
 * @author Mariya Vlaseva
 *
 * Methode: Countingsort
 * Status : Accepted
 * Runtime: 0.140
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.text.DecimalFormat;
import java.util.Locale;


public class Main {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String... args) throws IOException {

        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
        int testCase =1;

        for(String line = console.readLine(); line != null; line = console.readLine()) {
            if(line.trim().equals("")) continue;

            if (line.equals("0")){
                break;
            }       
            String[] splittArray = line.split("\\s+");
            double arg1 = Double.parseDouble(splittArray[1]);

            double arg2 = Double.parseDouble(splittArray[2]);
            double arg3 = Double.parseDouble(splittArray[3]);

            if (splittArray[0].equals("1")){
                calcAS(testCase, arg1, arg2, arg3);

            }
            else if (splittArray[0].equals("2")){
                calcST(testCase, arg1, arg2, arg3);
            }
            else if (splittArray[0].equals("3")){
                calcVT(testCase, arg1, arg2, arg3);

            }
            else {
                calcUT(testCase, arg1, arg2, arg3);
            }
            testCase++;

        }

    }

    private static void calcUT(int count, double v, double a, double s) {

        double u=Math.sqrt(v*v-2*a*s);
        double t=(v-u)/a;
        printResult(count, u, t);
    }

    private static void calcVT(int count, double u, double a, double s) {
        double v=Math.sqrt(u*u+2*a*s);

        double t=(v-u)/a;
        printResult(count, v, t);
    }

    private static void calcST(int count, double u, double v, double a) {
        double t=(v-u)/a;
        double s=(v*v-u*u)/(2*a);

        printResult(count, s, t);
    }

    private static void calcAS(int count, double u, double v, double t) {
        double a=(v-u)/t;
        double s=(v*v-u*u)/(2*a);
        printResult(count, s, a);

    }

    private static void printResult(int testCase, double arg1, double arg2) {
        DecimalFormat format = (DecimalFormat)DecimalFormat.getInstance(Locale.US );
        format.applyPattern( "#,###0.000" );   

        System.out.println("Case " + testCase + ": " + format.format(arg1) + " " + format.format(arg2));
    }
}



2.

/**
* Problem: 11715 Car
* Zeit: 0.092
* Programmiersprache: JAVA
* @author Christoph Miesel
* Status: ACCEPTED
*/


import java.util.*;
import java.io.*;

public class Car
{
public static String r(double d)
{
d *= 1000;
long tmp = Math.round(d);
d = (double)tmp / 1000;
boolean flag = false;
String s = "";

s += d;
int counter = 0;
for(int i = 0; i < s.length(); i++)
{
if(flag)
counter++;
if(s.charAt(i) == '.')
flag = true;
}
for(int i = 0; i < (3 - counter); i++)
s += "0";

return s;
}

public static void main(String[] args)throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();

long tmp;
double u,v,a,t,s;
int c,counter; //case
StringTokenizer token = new StringTokenizer(line);
counter = 0;
while(true)
{
c = Integer.parseInt(token.nextToken());
if(c == 0)
break;
switch(c)
{
case 1:
u = Double.parseDouble(token.nextToken());
v = Double.parseDouble(token.nextToken());
t = Double.parseDouble(token.nextToken());
s = u*t+0.5*(v-u)*t;
a = (v-u)/t;
++counter;

System.out.println("Case "+counter+": "+r(s)+" "+r(a));
break;
case 2:
u = Double.parseDouble(token.nextToken());
v = Double.parseDouble(token.nextToken());
a = Double.parseDouble(token.nextToken());
t = (v - u)/a;
s = u*t + 0.5*a*t*t;
++counter;
System.out.println("Case "+counter+": "+r(s)+" "+r(t));
break;
case 3:
u = Double.parseDouble(token.nextToken());
a = Double.parseDouble(token.nextToken());
s = Double.parseDouble(token.nextToken());
t = -u/a + Math.sqrt(u*u + 2*a*s)/a;
if(-u/a - Math.sqrt(u*u + 2*a*s)/a > t)
t = -u/a - Math.sqrt(u*u + 2*a*s)/a;
v = a*t + u;
++counter;
System.out.println("Case "+counter+": "+r(v)+" "+r(t));
break;
case 4:
v = Double.parseDouble(token.nextToken());
a = Double.parseDouble(token.nextToken());
s = Double.parseDouble(token.nextToken());
u = Math.sqrt(v*v - 2*a*s);
t = s/(u+0.5*(v-u));
++counter;
System.out.println("Case "+counter+": "+r(u)+" "+r(t));
break;
}
line = reader.readLine();
token = new StringTokenizer(line);
}
}
}