Wednesday, 9 March 2016

Java Tutorial : Java String(primitive Numbers to Strings-toString method)

NumberToStringDemo.java
/*
 * Converting Numbers to Strings.
 */
public class NumberToStringDemo
{

    public static void main(String[] args)
    {
        /*
         * Each of the Number subclasses includes a class
         * method, toString(), that will convert its
         * primitive type to a string.
         */
        double d = 543.48;
        String s = Double.toString(d);
        System.out.println("s = "+s);

        int dot = s.indexOf('.');

        System.out
                .println(dot + " digits " + "before decimal point.");
        System.out.println((s.length() - dot - 1)
                + " digits after decimal point.");
        
        int i = 190;
        String s3 = Integer.toString(i); 
        System.out.println("s3 = "+s3);

    }
}
Output
s = 543.48
3 digits before decimal point.
2 digits after decimal point.
s3 = 190
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringDemo_Numbers%20to%20Strings_toString_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_Numbers%20to%20Strings_toString_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/764ecf5c6cba932aee2ceef22ba699fc15012e37/BasicJava/StringDemo_Numbers%20to%20Strings_toString_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge