Q:

Java program to convert a short integer into a string

belongs to collection: Java Conversion Programs

0

Java program to convert a short integer into a string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to convert a short integer into the string is given below. The given program is compiled and executed successfully.

// Java program to convert a short integer 
// into a string

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner X = new Scanner(System.in);
    String str;
    short shortVal = 0;

    System.out.print("Enter short value: ");
    shortVal = X.nextShort();

    //Convert short value into string.
    str = Short.toString(shortVal);

    System.out.println("String value: " + str);
  }
}

Output:

Enter short value: 12345
String value: 12345

Explanation:

In the above program, we imported "java.util.Scanner" to read input from the user. And, created a Main class that contains a method main().

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to convert an integer array into the ... >>
<< Java program to convert byte into the string...