String to long in java

Java convert string to long using Long.parseLong() method package com.w3schools; public class StringToLong { public static void main(String args[]){ String str = “578115”; //convert string to long long num = Long.parseLong(str); System.out.println(num); } } Output: 578115 Download this example. Java convert string to long using Long.valueOf() method package com.w3schools; public class StringToLong { public static … Read more

Double to string in java

Java convert double to string using toString() method package com.w3schools; public class DouleToString { public static void main(String args[]){ double var = 551.101; String str = Double.toString(var); System.out.println(“String is: “+str); } } Output: String is: 551.101 Download this example. Java convert double to string using valueOf() method package com.w3schools; public class DouleToString { public static … Read more

Java String to double

Java converts string to double using Double.parseDouble(String) package com.w3schools; public class StringToDouble { public static void main(String args[]){ String str=”546.307″; //convert String to double double var= Double.parseDouble(str); System.out.println(var); } } Output 546.307   Java converts string to double using Double.valueOf(String) package com.w3schools; public class StringToDouble { public static void main(String args[]){ String str=”546.307″; //convert String … Read more

Java Int to string

Java int to string example using Integer.toString() The Integer.toString() method is used to convert int to string in Java. It takes an integer value as an argument and returns a string representing of it. package com.w3schools; public class IntToString { public static void main(String args[]){ int num = 123; String str = Integer.toString(num); System.out.println(“String is: … Read more

Java String to integer with leading zeros

The format() method of the String class is used to convert string to integer with leading zeros. Example: package com.w3schools; public class StringToInt { public static void main(String args[]){ String str=”000000575″; /* String to int conversion with leading zeroes * the * the number, this ensures the leading zeroes */ str = String.format( System.out.println(“Output String: … Read more

Java String to int

Java string to int example using Integer.parseInt() The Integer.parseInt() method is used to convert string to int in Java. It returns a primitive int value. It throws a NumberFormatException when all the characters in the String are not digits. Note: The first character in the string can be a minus ‘-‘ sign. Example: package com.w3schools; … Read more

Java examples programs

  Learn basic simple core java examples programs tutorial with output in eclipse online for hello world, java data types, if else statements, switch statement, for loop, enhanced for loop, while loop, do while loop and more.   Hello World java example: Java hello world example eclipse. Java data types examples programs: Java data types … Read more

Java Generate Pyramid Triangle

  Program to generate pyramid triangle example in java. /** * Program to generate pyramid triangle example in java. * @author W3schools360 */ public class GeneratePyramidTriangleExample { static void generatePyramidTriangle(int rows){ //Logic to generate pyramid triangle. for(int i=1; i<= rows; i++){ for(int j=0; j < i; j++){ System.out.print(“*”); } //New line. System.out.println(“”); } } public … Read more

Java Generate Pyramid For a Given Number

  Program to generate pyramid for a given number example in java. /** * Program to generate pyramid for a given number example in java. * @author W3schools360 */ public class GeneratePyramidExample { static void generatePyramid(int lines, int numDiff){ int y = 0; for(int i=0; i<= lines; i++){ for(int j=1; j <= i ; j++){ … Read more

Java Floyd Triangle

Program to Generate Floyd triangle example in java. /** * Program to generate Floyd triangle example in java. * @author W3schools360 */ public class FloydTriangle { static void generateFloydTriangle(int rows){ int num = 1; //Logic to generate Floyd’s triangle. for (int i = 1; i <= rows; i++) { for (int j = 1; j … Read more