I was doing this arrays program:
- Write a line of code that declares an array type
char
and initialize it with the string constant“Estudiando cadenas”
. The array must have a size that allows you to save the string without any element.
I did it like this:
public class VectorChar {
public static void main(String[] args) {
final int TOPE = 16;
final char arrayCaracter[]= {'E', 's', 't', 'u', 'd', 'i',
'a', 'n' ,'d', 'o' , 'c', 'a' , 'd', 'e', 'n' , 'a' , 's'};
arrayCaracter = new char [TOPE];
}
}
What I did was declare an array type char
with each of its characters in the string "Estudiando cadenas"
; I also put a variable limit that is what will indicate its dimension since in total they are 16 characters
but it gave me error, then look in Google examples of arrays type char
and change it to this:
public class VectorChar {
public static void main(String[] args) {
final char arrayCaracter[]= {'E', 's', 't', 'u', 'd', 'i',
'a', 'n' ,'d', 'o' , ' ', 'c', 'a' , 'd', 'e', 'n' , 'a' , 's'};
String salida = new String(arrayCaracter);
System.out.println(salida);
}
The only thing I left was the declaration of the array type char
, the String
I saw it in an example, so I tried and it worked, but my question is if really in the last change I made in the program is what it asks me in the slogan.