chevron_left

Problem:

Folks, I hope you are doing well. I started learning java programming very recently. I am on the chapter of Data Type right now of the book from where I am taking the help. There is a problem give in my book’s exercise that: “if you want to manually convert 65 to the letter a, what keyword is needed”?

I can’t really get the problem actually. Is it really possible to do so? If so, then how? Could you please give a hint regarding the problem given above?

Best regards.

Solution:

As I can understand you wanted to write a program where you can convert a number (65) into a letter (A) but you gave the title of your problem is, “Convert int to the string”

No worries. I am trying to make it easy for both cases as following below:

public class IntToString 
{ 
  public static void main(String args[]) 
  { 
    int a = 65; 
    String s = Integer.toString(a); 
    System.out.println("String s = " + s);  
  } 
}

On the above code, I used the function Integer.toString() it helps to cast an integer number into a string type.

public class IntToChar
{
  public static void main(String args[])
  {
    int a1 = 65;          
    char ch = (char) a1;
    System.out.println("Integer value: " + a1);
    System.out.println("Char value: " + ch);
  }
}

I really hope it might help you.

More Posts

How to check if a character is a number in java? Gavin - Mar 18, 2020
How to append a character to a string in Java mhfaisal - Jul 9
How to convert char[] to string in C# mhfaisal - Jun 2
How to convert char to string in C++? Lalit Kumar - May 12, 2020
How to convert string to char in C++? Lalit Kumar - May 10, 2020
compare a character in java DivyaN - Aug 8
How to convert an int to a string in java MallikaShaik672 - Nov 1, 2020
How to count number of words in a string in java kesav.eee - Aug 12
How to count the number of occurrences of a character in a string in java Hasnain_khan - Oct 13, 2020
How to Add a Char to a String in C++? Lalit Kumar - Sep 6, 2020