shaqm Posted October 19, 2009 at 04:00 PM Report Share #292356 Posted October 19, 2009 at 04:00 PM Boas, tenho um método recursivo para fazer para a faculdade, já tenho o código e o método funciona para arrays ordenados, mas não para desordenados, eu a programar recusrsivo é sempre à "martelada" e depois vejo no debug o que está mal, mas com o windows7 dá um bug no eclipse e não consigo correr o debug, aqui vai o problema: public static int[] lastTwo( int val ) que retorna um array de dois inteiros contendo os dois algarismos de maior peso na base decimal do valor val. Caso o valor absoluto de |val| seja menor que 10 retorna null. o código que eu fiz: package grupo1; public class LastTwo { public static int[] lastTwo( int val ){ int []a=new int[2]; if(Math.abs(val) < 10)return null; if(val < 100){ if(val%10 < val/10){ a[0]=val%10; a[1]=val/10; return a; }else { a[1]=val%10; a[0]=val/10; return a; } } if(val%10 > lastTwo(val/10)[0]){ if(val%10 > lastTwo(val/10)[1]){ a[1]=val%10; a[0]=lastTwo(val/10)[1]; return a; }else{ a[0]=val%10; return a; } }else return a; } } alguém me csg dar uma mãozinha?tks in advance 😁 Link to comment Share on other sites More sharing options...
shaqm Posted October 29, 2009 at 02:16 PM Author Report Share #293856 Posted October 29, 2009 at 02:16 PM Já csg fazer o debug e encontrei o problema, mas não o csg resolver: public static int[] lastTwo( int val ){ int []a=new int[2]; if(Math.abs(val) < 10)return null; if(val < 100){ if(val%10 < val/10){//quando retorna a os valores do array ficam a zero! a[0]=val%10; a[1]=val/10; return a; }else { a[1]=val%10; a[0]=val/10; return a; } } if(val%10 > lastTwo(val/10)[0]){ if(val%10 > lastTwo(val/10)[1]){ a[1]=val%10; a[0]=lastTwo(val/10)[1]; return a; }else{ a[0]=val%10; return a; } }else return a; } Sugestões? Link to comment Share on other sites More sharing options...
M6 Posted October 29, 2009 at 05:01 PM Report Share #293884 Posted October 29, 2009 at 05:01 PM Assim de repente creio que há situações onde o array não foi inicializado... 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now