answersLogoWhite

0


Best Answer

It depends on what you mean by "convert an int to char".

If you simply want to cast the value in the int, you can cast it using Java's typecast notation:

int i = 97; // 97 is 'a' in ASCII

char c = (char) i; // c is now 'a'

If you mean transforming the integer 1 into the character '1', you can do it like this:

if (i >= 0 && i <= 9) {

char c = Character.forDigit(i, 10);

....

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

You cannot do that. A character array in java can take only character values in it. If we try to insert a integer value, we will get an exception because the character array is not designed to accept non character values.

Similarly if you try to put a character value inside an integer array you will get exactly the same error.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

ASCII is a character encoding scheme that encodes 128 specific characters (English alphabet - 7 bits). Assuming you have the ASCII code 65 you want to convert that to an "A". This can be done by casting the code to a char:

char c = (char)65;

System.out.println(c); // prints A

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

(char) (i + '0');

or

Character.forDigit(i, 10);

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

char can hold only positive integer values. Therefore, a negative int cannot be converted into a char.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you insert an integer value to a character array in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you convert an integer to Boolean array list in java?

You cannot. An Integer is a numeric value whereas a boolean array list is a collection of a number of true or false values. So, you cannot convert either into the other


Can an integer data type in c plus plus stores character value?

no


Why character is an integer?

A character type (char) is not an integer, but it is an integral type and can therefore be used to store integers and perform integral arithmetic. However, in order to output the value as an integer rather than as a character code, the character must be converted (cast) to an integer. This can be done explicitly or implicitly. The only thing to be wary of is when mixing signed/unsigned representations as this may cause narrowing.


What restriction must be satisfied by all of the data items represented by an array?

An array is a group of related items that share a common name.All these elements are stored consecutively. An array must be declared before its use in the program. Array size must be specified All Array elements must be assigned to any value for assignment the value. Partial initialization of elements of an array is not allowed. Size must be integer constant enclosed within square brackets The name of the array indicates starting address of an array. Each individual element of array is accessed by a subscript.


Maximum value of an array?

The maximum number of elements will depend on the type of array and the available memory. An array of char requires only 1 byte per element but an array of pointers requires 4 bytes per element (8 bytes on 64-bit systems). Arrays of objects or structures would likely require more memory per element.For all practical purposes, the maximum size is 2,147,483,647 elements, which is the maximum positive range for a 4-byte integer (0x7FFFFFFF). At 1 byte per element, that works out at 2GB.

Related questions

What is the default value of the array elements in an integer array?

'0' Try this: public static void main(String[] args){ } The output would be 0 even though you did not initialize any value in the int array.


How do you convert an integer to Boolean array list in java?

You cannot. An Integer is a numeric value whereas a boolean array list is a collection of a number of true or false values. So, you cannot convert either into the other


True or false the controlling expression of a switch statement must have a value that is an integer or a character?

False. In C++, it must evaluate to an integral type, which includes floating point types. In other languages, a character array or other object may also be acceptable.


What advantage are there in defining an array size in term of symbolic constant rather than a fixed integer value?

It may be possible to generalise results to other integer values.


Can an integer data type in c plus plus stores character value?

no


How do you write a java method to find the second largest integer in an array by using only one loop?

Use two variables to store the largest, and the second-largest integer. Update those in a loop, for every element in the array. Initial values might be the lowest permissible value for the int, long, double, or whatever value you use.


How do you get the absolute value of positive integer?

The absoluate value of a positive integer is the integer itself.The absoluate value of a positive integer is the integer itself.The absoluate value of a positive integer is the integer itself.The absoluate value of a positive integer is the integer itself.


What is array in C languange?

An array is a contiguous block of data in memory. When you declare an array in C you need to give it a type and a name (like a normal variable), plus you need to give it a size. // normal integer variable x int x; // array of 10 integers int x[10]; Remember that the variable x is actually just a pointer, or reference, to a point in memory. This point in memory is the start of the array, so the value at x[0] is the first value in the array, x[1] is the second, and so on. Also remember that C has no bounds checking, so you can, indeed, read any value past the maximum. x[3474] would return an integer value, but it's going to be some part of memory that is not in your array. Attempting to change this value could result in something very bad happening.


Why character is an integer?

A character type (char) is not an integer, but it is an integral type and can therefore be used to store integers and perform integral arithmetic. However, in order to output the value as an integer rather than as a character code, the character must be converted (cast) to an integer. This can be done explicitly or implicitly. The only thing to be wary of is when mixing signed/unsigned representations as this may cause narrowing.


What restriction must be satisfied by all of the data items represented by an array?

An array is a group of related items that share a common name.All these elements are stored consecutively. An array must be declared before its use in the program. Array size must be specified All Array elements must be assigned to any value for assignment the value. Partial initialization of elements of an array is not allowed. Size must be integer constant enclosed within square brackets The name of the array indicates starting address of an array. Each individual element of array is accessed by a subscript.


Differentiate string and character?

A character is an integer value which stores an encoding for a printable (though not necessarily "visible") symbol. A string is a list of characters.


Function pointer that will point to a function that takes integer value and return character?

Answerchar (*funcp(int));