Question

In: Computer Science

In a Package called characterArray, ********JAVA CODE********** 1) Create a char array containing your full name...

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.

Solutions

Expert Solution

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());
        }

    }
}

====================================================================


Related Solutions

Write the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
Test Your Understanding Create a JAVA package by name ClassEx2 and in the main() method of...
Test Your Understanding Create a JAVA package by name ClassEx2 and in the main() method of the class, assign your name to a String object and your father name to a different String object and do the following; Concatenate your name and your father name. Get the length of your full name. Find the index of any character in your full name. Replace the occurrence of any lower case character in your full name to capital character. Compare your first...
In STS, create Java Project, called java_generics_yourNameLastname that; (Under source directory called, src, create a package...
In STS, create Java Project, called java_generics_yourNameLastname that; (Under source directory called, src, create a package csci3444.generics and put all code in it) Create a generic interface called “MyGenInterface” that takes 2 generic types K,V with below methods; public K getKey(); public V getValue(); Create a generic class called “MyGenClass” that implements “MyGenInterface” interface. has attributes “K key” and “V value” that can be inherited has a constructor that takes “K _key”, “V _value” inputs and initializes “key”, “value” attributes...
Create a Java class with the name (identifier) MyProgram and place it in the Questions package....
Create a Java class with the name (identifier) MyProgram and place it in the Questions package. You will need to create a main method for this class and place all of your code inside of that method. Your program should complete the following steps: - Prompt the user to enter a name for a Student. - Use the Scanner class to read in the user input and store the result in a variable. - Use the Random class to generate...
You need a data structure that contains fields for name (char array), color (char array), age...
You need a data structure that contains fields for name (char array), color (char array), age (int), and height (int). Name the struct Info when you define it. Create a function named getUserInfo() that asks the user for name, color, age, and height and then returns a data structure containing that information. It should do the following: What is your name? George What is your favorite color? Green What is your age? 111 What is your height in inches? 72...
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
Create a Word file containing the following: The full name of the “test subject” The test...
Create a Word file containing the following: The full name of the “test subject” The test subject is a person, not yourself, who can say the names of the products. The best test subject is one who is adamant about being an expert who can distinguish brand A from B. You cannot be the test subject because you generate the sequence, and the test subject cannot see it for an unbiased test. Pets and babies are not allowed as they...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20];...
Create a structure in C called BarcelonaPlayer with the following members. struct BarcelonaPlayer { char name[20]; int age; char country[20]; char Position[20]; double Salary; double Rating; }; First, create an array of BarcelonaPlayer structures. Now, write a function that takes an array of BarcelonaPlayer structures as input and find out the highest paid player among all the players. void highestPaidPlayer(struct BarcelonaPlayer *pl, int size); Create another function that finds all the players from Argentina. void findPlayers(struct BarcelonaPlayer *pl, int size);
JAVA CODE Give the definition of a static method called showArray that has an array of...
JAVA CODE Give the definition of a static method called showArray that has an array of base type char as a single parameter and that writes to the screen each character in the array on a separate line. It then writes the same array characters in reverse order. This method returns a character array that holds these two lines of characters in the order that you printed them.
JAVA CODE Give the definition of a static method called showArray that has an array of...
JAVA CODE Give the definition of a static method called showArray that has an array of base type char as a single parameter and that writes to the screen each character in the array on a separate line. It then writes the same array characters in reverse order. This method returns a character array that holds these two lines of characters in the order that you printed them.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT