elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


  Mostrar Mensajes
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 [13] 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ... 128
121  Programación / Java / Re: [SRC] decimalToRomano en: 22 Noviembre 2011, 21:08 pm
Ya veo...
¿Alguna ventaja en especial de una clase sobre otra? :huh:

Me veréis mucho por aquí, ahora que empecé con Java. :)
Yuju!

DoEvents! :P
122  Programación / Java / Re: [SRC] isPrime en: 22 Noviembre 2011, 21:05 pm
Oukei, me comeré el "==" en esos casos.
Gracias.

DoEvents! :P
123  Programación / Java / [SRC] isPrime en: 22 Noviembre 2011, 20:53 pm
La mejor forma que se me ocurre de hacerlo:

Código
  1.    public static boolean isPrime(int iNum) { // La forma más rápida que se me ocurre
  2.     if (iNum > 1) {
  3.     if (iNum < 6){
  4.     if (iNum == 2 || iNum == 5 || iNum == 3)
  5.     return true;
  6.     } else if (((iNum & 1) == 1) && ((iNum % 10) != 5)) {
  7. long lRaiz = (long) Math.sqrt(iNum);
  8. long x;
  9.  
  10. for (x=3; x <= lRaiz; x += 2){
  11. if ((iNum % x) == 0)
  12. return false;
  13. };
  14.  
  15. return true;
  16.     }
  17.     }
  18.     return false;
  19.    }

DoEvents! :P
124  Programación / Java / Re: [SRC] decimalToRomano en: 22 Noviembre 2011, 20:40 pm
Lo de la notación húngara es una costumbre que tomé con vb6, como tú bien dices, por lo poquísimo que he visto en Java no se usa, pero a mí me resulta muy útil a veces, sobretodo si tengo muchas variables. :)

Sé que podía omitir ese punto y coma, pero así me parecía que quedaba un poco más claro, ¿no crees? :P

¿BufferReader?
No lo he usado hasta ahora, voy a probar. Gracias. ;)

DoEvents! :P

125  Programación / Java / [SRC] decimalToRomano en: 22 Noviembre 2011, 20:05 pm
Llevo muy poco en java, avisadme si veis algún error o algo mejorable, a ver que os parece:

Código
  1. import java.util.*;
  2.  
  3. public class Hello {
  4. public static String repeatString(String sText, int iTimes){
  5. return new String(new char[iTimes]).replace("\0", sText);
  6. }
  7.  
  8. public static String decimalToRomano(int iNum) {
  9. int iTmp= 0, i= 1;
  10. String sRet= "";
  11.  
  12. String [] [] sRDigit =
  13. {
  14. {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
  15. {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
  16. {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}
  17. };
  18.  
  19. if (iNum > 0){
  20. for (int x=0; x<3; x++){
  21. iTmp=iNum % (i * 10);
  22.  
  23. if (iTmp != 0)
  24. sRet= sRDigit[x][(iTmp / i) -1] + sRet;
  25.  
  26. iNum -= iTmp;
  27.  
  28. if (iNum == 0)
  29. return sRet;
  30.  
  31. i *= 10;
  32. };
  33.  
  34. sRet= repeatString("M", iNum / 1000) + sRet;
  35. };
  36.  
  37. return sRet;
  38. }
  39.  
  40. public static void main (String args[]) {
  41. System.out.println("Dame un numero mayor que cero para convertirlo a un numero romano:");
  42.  
  43. int iMyNum = new Scanner(System.in).nextInt();
  44. System.out.println("El numero "+ iMyNum + " en romano es: " + decimalToRomano(iMyNum));
  45. }
  46. }

DoEvents! :P
126  Programación / Programación Visual Basic / Re: [RETO] Recortar cadena. en: 23 Octubre 2011, 21:50 pm
A mí no me crashea con más de tres llamadas... :rolleyes:
Prueba a quitar el Static por si acaso...

DoEvents! :P
127  Programación / Programación Visual Basic / Re: La mejor forma de autoeliminarse? Reto? :P en: 23 Octubre 2011, 20:38 pm
Lo digo porque no es la primera vez que pides ayuda y lo camuflas como reto para que responda la gente. :¬¬
Y por cierto, ese código que has puesto lo detectan los Avs a la primera. :silbar: :xD

DoEvents! :P
128  Programación / Programación Visual Basic / Re: La mejor forma de autoeliminarse? Reto? :P en: 23 Octubre 2011, 18:46 pm
RETO <> Deberes

DoEvents! :P
129  Programación / Programación Visual Basic / Re: [RETO] Recortar cadena. en: 23 Octubre 2011, 15:55 pm
Vale todo el más rápido gana.
>:D

 >:D

Código
  1. Option Explicit
  2. Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Long)
  3. Private Declare Function SysAllocStringByteLen Lib "oleaut32.dll" (ByVal oleStr As Long, ByVal BLen As Long) As Long
  4.  
  5. Public Static Function RemoveStr_Psyke1(ByVal sText As String, ByVal lPosIni As Long, ByVal lLen As Long) As String
  6. Dim lLenB                                   As Long
  7. Dim lpString                                As Long
  8.  
  9.    lLenB = LenB(sText)
  10.    If lLenB Then
  11.        If (lPosIni Or lLen) And &H80000000 Then Exit Function
  12.  
  13.        lLen = (lLen + lLen)
  14.        lPosIni = (lPosIni + lPosIni)
  15.  
  16.        If (lPosIni + lLen) = lLenB Then lLen = lLenB
  17.  
  18.        If (lLen = lLenB) And (lPosIni = 0&) Then
  19.            RemoveStr_Psyke1 = sText
  20.            Exit Function
  21.        End If
  22.  
  23.        lpString = StrPtr(sText)
  24.  
  25.        RtlMoveMemory (lpString + lPosIni), (lpString + lPosIni + lLen), (lLenB - lPosIni + lLen)
  26.        RtlMoveMemory VarPtr(RemoveStr_Psyke1), VarPtr(SysAllocStringByteLen(lpString, lLenB - lLen)), 4&
  27.    End If
  28. End Function
  29.  
  30. Private Sub Form_Load()
  31.    MsgBox RemoveStr_Psyke1("hola amigo 123456789", 4, 6)
  32. End Sub

DoEvents! :P
130  Programación / Programación Visual Basic / Re: [RETO] Recortar cadena. en: 23 Octubre 2011, 13:38 pm
Más tarde publico la mía.


DoEvents! :P
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 [13] 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ... 128
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines