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...
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...
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 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.
1.Write the java code to create a two dimensional String array of sizes 12 by 8;...
1.Write the java code to create a two dimensional String array of sizes 12 by 8; Given the java array:       double[] test = new double[3]; 2.  Write the java code to put the numbers 1.0, 2.0, and 3.0 in to the array so that the 1.0 goes in the first cell, the 2.0 goes in the second cell and the 3.0 goes in the third cell. 3. Can you have different types of data is a three dimensional array? 4....
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...
Part 1: Create a character array and save your first and last name in it
PROGRAMMING IN C:Part 1:Create a character array and save your first and last name in itNote: You can assign the name directly or you can use the scanf function.Display your name on the screen.Display the address (memory location) in hexadecimal notation of the array. (hint: use %p)Use a for loop to display each letter of your name on a separate line.Part 2:Create a one dimensional array and initialize it with 10 integers of your choice.Create a function and pass the...
Write a Java method that takes an array of char and a String as input parameters...
Write a Java method that takes an array of char and a String as input parameters and and returns an boolean. The method returns true if we can find the input string inside the array by starting at any position of the array and reading either forwards or backwards.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT