In: Computer Science
In a Package called characterArray, ********JAVA
CODE**********
1) Create a char array containing your full name and print it
out.
2) Create an uninitialized char array and copy into it
the char array containing your full name
and print it out.
3) Create a Character array and copy into it the char array
containing
your full name and print it out.
4) Into the Character array, use toUpperCase() to copy the char
array containing
your full name and print it out.
5) Convert the Characters in place using toLowerCase() and
charValue()
to lowercase Characters.
thanks for the question, here is the code in Java, when you run the program please update the char array with yoru full name.
Comments given for you to identify the code for each sub parts
========================================================================
public class CharArray {
public static void
main(String[] args) {
// 1. Create a char
array containing your full name
System.out.println("Part
1");
char
name[] = {'B', 'a',
'r', 'a', 'c',
'k', ' ', 'O',
'b', 'a', 'm',
'a'};
// print it out
for
(int i = 0; i < name.length;
i++) {
System.out.printf("%c",
name[i]);
}
System.out.println("\n\nPart
2");
// 2 Create an
unitialized char array and copy into it
char
duplicate[] = new
char[name.length];
for
(int i = 0; i < name.length;
i++) duplicate[i] = name[i];
// print it out
for
(int i = 0; i < name.length;
i++) {
System.out.printf("%c",
duplicate[i]);
}
System.out.println("\n\nPart
3");
//3. Create a Character
array
Character
duplicateObject[] = new
Character[name.length];
for
(int i = 0; i < name.length;
i++) duplicateObject[i] = new
Character(name[i]);
// print it out
for
(int i = 0; i < name.length;
i++) {
System.out.printf("%c",
duplicateObject[i]);
}
System.out.println("\n\nPart
4");
//5. use to UpperCase to
copy the char array
for
(int i = 0; i < name.length;
i++) duplicateObject[i] =
Character.toUpperCase(duplicateObject[i]);
for
(int i = 0; i < name.length;
i++) {
System.out.printf("%c",
duplicateObject[i]);
}
System.out.println("\n\nPart
5");
// 6. Convert the
characters to lower case using tolowercae and charvalue
for
(int i = 0; i < name.length;
i++)
duplicateObject[i] =
Character.toLowerCase(duplicateObject[i]);
for
(int i = 0; i < name.length;
i++) {
System.out.printf("%c",
duplicateObject[i].charValue());
}
}
}
====================================================================