Méthode Java Integer class toOctalString() avec exemple
Méthode classe entière versOctalString()
- méthode toOctalString() est disponible dans le package java.lang.
- méthode toOctalString() est utilisé pour représenter une chaîne octale du paramètre donné [valeur] de type entier sous la forme d'un entier non signé en base 8.
- méthode toOctalString() est une méthode statique, elle est également accessible avec le nom de la classe et si nous essayons d'accéder à la méthode avec l'objet de la classe, nous n'obtiendrons pas non plus d'erreur.
- méthode toOctalString() ne lève pas d'exception au moment de la conversion d'entier en chaîne octale.
Syntaxe :
public static String toOctalString (int value);
Paramètre(s) :
- int value – représente la valeur entière à convertir.
Valeur renvoyée :
Le type de retour de cette méthode est int, elle retourne la chaîne octale du paramètre donné qui représente la valeur entière non signée.
Exemple :
// Java program to demonstrate the example // of toOctalString (int value) method of Integer class public class ToOctalStringOfIntegerClass { public static void main(String[] args) { // Variables initialization int i1 = 10; int i2 = 20; int i3 = 30; int i4 = Integer.MAX_VALUE; int i5 = Integer.MIN_VALUE; // Integer instance creation Integer value = new Integer(i1); // It represents Octal string of the given // integer type i2 argument String s = value.toOctalString(i2); // Display Octal String Representation System.out.println("value.toOctalString(i2): " + s); // It represents Octal string of the given // integer type i3 argument s = value.toOctalString(i3); // Display Octal String Representation System.out.println("value.toOctalString(i3): " + s); // It represents Octal string of the given // integer type i4 argument s = value.toOctalString(i4); // Display Octal String Representation System.out.println("value.toOctalString(i4): " + s); // It represents Octal string of the given // integer type i5 argument s = value.toOctalString(i5); // Display Octal String Representation System.out.println("value.toOctalString(i5): " + s); } }
Sortie
value.toOctalString(i2): 24 value.toOctalString(i3): 36 value.toOctalString(i4): 17777777777 value.toOctalString(i5): 20000000000