1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #11185 (Ternary)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=2126
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 05/10/2009
*
* Status : Accepted
* Runtime: 0.084
*/

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

public class Main {

/**
* baseThree
*
* This method converts a decimal number into a Base 3 stream
*
* @param n: An integer (decimal system)
* @return ArrayList[Integer], where the highest bit has the highest index
*
*/
public static ArrayList<Integer> baseThree(int n)
{
ArrayList<Integer> result = new ArrayList<Integer>();
do
{
result.add(n%3);
n /= 3;
}
while(n!=0);

return result;
}

public static void main (String[] args) throws IOException
{
//set up variables needed;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder answer = new StringBuilder();
String line;
int number;
ArrayList<Integer> binaryDigits;

while(true)
{
//read-in
line = reader.readLine();

if(line == null)
break;

number = Integer.parseInt(line);

if(number<0)
break;

//convertion
binaryDigits = baseThree(number);

//append to StringBuilder beginning with the highest bit
for(int i=binaryDigits.size()-1;i>=0;i--)
answer.append(binaryDigits.get(i));

answer.append("\n");

}

System.out.print(answer.toString());
}

}

2.

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

/**
* Angewandte Mathematik SS09
* ACM Problem 11185 - Ternary
*
* @author M. Stadler
* @author J. M�ller
* @version 1.0
*
* Status : Accepted
* Runtime: 0.096
*/

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

BufferedReader foo = new BufferedReader(new InputStreamReader(System.in));
String input;

try {
while ((input = foo.readLine()) != null) {
long dez = Long.parseLong(input);
long tmp = 0;

StringBuilder base = new StringBuilder();
if (dez < 0) // wenn negativ dann abrechen
System.exit(0);

if (dez == 0)
System.out.print(0);

while(dez != 0) {
tmp = dez%3;

base.insert(0, tmp);
dez /= 3;
}

System.out.println(base.toString().trim());

}


} catch (IOException e) {

}
}

}

3.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 11185 - Ternary
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=23&problem=2126&mosmsg=Submission+received+with+ID+7130522
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version 1.0 15.05.2009
*
* Status : Accepted
* Runtime: 0.124
*/
import java.util.*;

public class Main
{
public static void main(String[] args)
{
int dez = 0;
StringBuilder ter = new StringBuilder();
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
dez = sc.nextInt();
if(dez < 0)
break;
if(dez == 0)
{
System.out.println(0+"");
continue;
}
while(dez != 0)
{
ter.insert(0, dez%3);
dez/=3;
}
System.out.println(ter.toString());
ter = new StringBuilder();
}
}
}

4.

/**
* 11185 - Ternary
*
* Studiengruppe: IFB2C
*
* Martin Pesl
* Robert Reichart
* Elvin Uzeirovic
*
* Run Time Submission Date
* 0.092 2009-05-13 09:28:54
*/

import java.io.*;

class Main{
public static void main(String... args)throws Exception{
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
String line = is.readLine();
while (Integer.parseInt(line)>=0){
System.out.println(umwandlung(Integer.parseInt(line)));
line = is.readLine();
}
}


static String umwandlung(int zahl) {
int rest;
String ergebnis="";

do {
rest = zahl % 3;
ergebnis = rest + ergebnis;
zahl = zahl / 3;
} while (zahl>0);

return ergebnis;
}
}