class Funcoes { public static float ElevaRec( float b, int e ) { if( e == 0 ) return 1; if( b == 0 ) return 0; return b * ElevaRec( b, e - 1 ); } public static float Eleva( float b, int e ) { if( e == 0 ) return 1; if( b == 0 ) return 0; float result = 1; for( int i = 0; i < e; result *= b, i++ ); return result; } } public class Potencia { public static void main( String args[] ) { if (args.length < 2) { System.out.println("Sintaxe: java -cp . Potencia metodo x y"); System.out.println(" metodo = R ==> Recursivo"); System.out.println(" L ==> Não Recursivo"); System.exit(0); } Double base = new Double( args[1] ); int expoente = Integer.parseInt( args[2] ); int expaux = expoente; if( expoente < 0 ) expaux *= -1; float result = args[0].indexOf( "R" ) != -1 ? Funcoes.ElevaRec( base.floatValue( ), expaux ) : Funcoes.Eleva( base.floatValue( ), expaux ); if( expoente < 0 ) result = ( 1 / result ); else result = result; System.out.println( base.floatValue( ) + " elevado a " + expoente + " ("+args[0]+") = "+ result ); } }