ADVERTISEMENT
ADVERTISEMENT

Java program to convert a short integer into a string

Given/input a short integer, we have to convert it into a string.
Submitted by Nidhi, on March 15, 2022

Problem Solution:

In this program, we will read a short value from the user and convert the input short value into the string Short.toString() method.

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().

The main() method is the entry point for the program, here we read a short value from the user using the Scanner class. Then we converted the input short value into a string using the Short.toString() method and printed the result.

Java Conversion Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.