La methode "parseInt " permet de recuperer un int a partir d'un String
mais comment marche valueOf ? Je ne vois pas ce qu'est un radix. Ca
apparait souvent dans les methodes.
valueOf
public static Integer valueOf(String s, int radix)
throws NumberFormatExceptionReturns an Integer object holding the
value extracted from the specified String when parsed with the radix
given by the second argument. The first argument is interpreted as
representing a signed integer in the radix specified by the second
argument, exactly as if the arguments were given to the parseInt
(java.lang.String, int) method. The result is an Integer object that
represents the integer value specified by the string. In other words,
this method returns an Integer object equal to the value of:
new Integer(Integer.parseInt(s, radix))
Parameters:
s - the string to be parsed.
radix - the radix to be used in interpreting s
Returns:
an Integer object holding the value represented by the string argument
in the specified radix.
Throws:
NumberFormatException - if the String does not contain a parsable int.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Albert
artintel a écrit :
La methode "parseInt " permet de recuperer un int a partir d'un String mais comment marche valueOf ? Je ne vois pas ce qu'est un radix. Ca apparait souvent dans les methodes.
c'est la "base" au sens mathématique. Pour les nombres décimaux (les plus courants), c'est la base 10, mais il y a aussi la base 2 et la base 16 qui sont connues en informatique.
artintel a écrit :
La methode "parseInt " permet de recuperer un int a partir d'un String
mais comment marche valueOf ? Je ne vois pas ce qu'est un radix. Ca
apparait souvent dans les methodes.
c'est la "base" au sens mathématique. Pour les nombres décimaux (les
plus courants), c'est la base 10, mais il y a aussi la base 2 et la base
16 qui sont connues en informatique.
La methode "parseInt " permet de recuperer un int a partir d'un String mais comment marche valueOf ? Je ne vois pas ce qu'est un radix. Ca apparait souvent dans les methodes.
c'est la "base" au sens mathématique. Pour les nombres décimaux (les plus courants), c'est la base 10, mais il y a aussi la base 2 et la base 16 qui sont connues en informatique.
Alain Ketterlin
artintel writes:
La methode "parseInt " permet de recuperer un int a partir d'un String mais comment marche valueOf ?
System.out.println("En base 10 : "+base10); System.out.println("En base 2 : "+base2); System.out.println("Par défaut : "+defaut);
} }
-------------------------------------------------- En base 10 : 11001011 En base 2 : 203 Par défaut : 11001011 --------------------------------------------------
:-)
"artintel" a écrit dans le message de news:
Parameters:
s - the string to be parsed.
radix - the radix to be used in interpreting s
class PourTests {
public static void main(String[] args) {
String nombre;
nombre="11001011";
System.out.println("En base 10 : "+base10);
System.out.println("En base 2 : "+base2);
System.out.println("Par défaut : "+defaut);
}
}
--------------------------------------------------
En base 10 : 11001011
En base 2 : 203
Par défaut : 11001011
--------------------------------------------------
System.out.println("En base 10 : "+base10); System.out.println("En base 2 : "+base2); System.out.println("Par défaut : "+defaut);
} }
-------------------------------------------------- En base 10 : 11001011 En base 2 : 203 Par défaut : 11001011 --------------------------------------------------
:-)
artintel
On 2 sep, 22:39, "JavaBeaucoupMieux" <@> wrote:
"artintel" a écrit dans le message de news:
> Parameters: > s - the string to be parsed. > radix - the radix to be used in interpreting s
class PourTests {
public static void main(String[] args) { String nombre; nombre="11001011";
System.out.println("En base 10 : "+base10); System.out.println("En base 2 : "+base2); System.out.println("Par défaut : "+defaut);
}
}
-------------------------------------------------- En base 10 : 11001011 En base 2 : 203 Par défaut : 11001011 --------------------------------------------------
:-)
Merci a tous pour vos reponses ;o)
On 2 sep, 22:39, "JavaBeaucoupMieux" <@> wrote:
"artintel" a écrit dans le message de news:
> Parameters:
> s - the string to be parsed.
> radix - the radix to be used in interpreting s
class PourTests {
public static void main(String[] args) {
String nombre;
nombre="11001011";
System.out.println("En base 10 : "+base10);
System.out.println("En base 2 : "+base2);
System.out.println("Par défaut : "+defaut);
}
}
--------------------------------------------------
En base 10 : 11001011
En base 2 : 203
Par défaut : 11001011
--------------------------------------------------
System.out.println("En base 10 : "+base10); System.out.println("En base 2 : "+base2); System.out.println("Par défaut : "+defaut);
}
}
-------------------------------------------------- En base 10 : 11001011 En base 2 : 203 Par défaut : 11001011 --------------------------------------------------