Saturday 13 October 2018





How to convert int to String in java?

package govind;

public class StringToIntConversion
{
public static void main(String[] args) {
int x=100;
String s1 = String.valueOf(x);
System.out.println(s1);//Now it will return "100"
System.out.println(x+400);//500 because + is binary plus operator
System.out.println(s1+400);//100400 because + is string concatenation operator
int y=200;
String s2 = Integer.toString(y);
System.out.println(s2);//"200"
System.out.println(s2+400);//200400 because + is string concatenation operator
int z=300;
String s3 = String.format("%d", z);
System.out.println(s3);//"300"
System.out.println(s3+400);//300400 because + is string concatenation operator
}
}


//op:----------------------------

100
500
100400
200
200400
300
300400

No comments:

Post a Comment