Java Program to Convert Int to String

Write a Java program to convert int to string. In Java, we can use String valueOf and format, or Integer.toString() methods to convert integer to string. This Java example accepts the user input integer and converts it to string using the valueOf function.

package NumPrograms;

import java.util.Scanner;

public class IntToString1 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Integer Value =  ");
		int i = sc.nextInt();
		
		String s1 = String.valueOf(i);

		System.out.println(s1);
		System.out.println(s1 + 100);
		System.out.println(i + 100);
	}
}
Java Program to Convert Int to String

Java program to convert int to string using the Integer toString method.

package NumPrograms;

import java.util.Scanner;

public class IntToString2 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Value =  ");
		int i = sc.nextInt();
		
		String s1 = Integer.toString(i);

		System.out.println(s1);
		System.out.println(s1 + 200);
		System.out.println(i + 200);
	}
}
Enter Any Value =  168
168
168200
368

This Java example uses the format method to convert a string to an integer.

package NumPrograms;

import java.util.Scanner;

public class IntToString3 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Number =  ");
		int i = sc.nextInt();
		
		String s1 = String.format("%d", i);

		System.out.println(s1);
		System.out.println(s1 + 200);
		System.out.println(i + 200);
	}
}
Enter Any Number =  130
130
130200
330

Let me use all the available options in Java to convert integer to string in one program.

package NumPrograms;

import java.util.Scanner;

public class IntToString4 {
	private static Scanner sc;	
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);	
		
		System.out.print("Enter Any Number =  ");
		int i = sc.nextInt();
		
		String s1 = String.valueOf(i);
		System.out.println(s1);
		
		String s2 = Integer.toString(i);
		System.out.println(s2);
		
		String s3 = String.format("%d", i);
		System.out.println(s3);
		
		System.out.println(s1 + 200);
		System.out.println(s2 + 200);
		System.out.println(s3 + 200);

	}
}
Enter Any Number =  120
120
120
120
120200
120200
120200