Question

In: Computer Science

Java programming language: 1.      Create a new Netbeans project called ArrayLoop. 2.      Declare a fixed length array of...

Java programming language:

1.      Create a new Netbeans project called ArrayLoop.

2.      Declare a fixed length array of integers which can store 8 elements. Do not assign any values.

int[] myAddresses = new int[8];

3.      Create a statement which raises 2 to the power of your loop counter, then subtracts 1, and assigns that value to the corresponding element. For example, when i = 3, 2 to the third power is 8, minus 1 = 7. When i = 4, 2 to the fourth power is 16, minus 1 = 15. Etc etc for all values of i.

Fill up the entire array with these values.

4.      Use Array.toString to print out the entire Array to the console.

5.      Create another FOR loop which counts from 8 down to 1.

6.      Use the counter values as indexes to print out your Array values in REVERSE order, from largest to smallest.

7.      Create a String object which stores your last name. Mine would be myName = "Hughes";

8.      Use the .length field to find the number of char's in your name. Use that value in a new FOR loop. This loop will print out the letters of your name one at a time. For example, my output should be:

H

u

g

h

e

s

TIP: Watch out for the 'Off by one' error.

9.      SCREENSHOT AND PRINT all source code in Notepad++.

a.      MARK AND LABEL the line which defines a FOR loop

b.      MARK AND LABEL the line which declares your integer Array.

c.       MARK AND LABEL the line which stores your computed values in the Array.

d.      MARK AND LABEL the line which prints out an entire Array at once.

e.       MARK AND LABEL a line which uses a loop counter as an Array index.

f.        MARK AND LABEL a line which finds the length of your name.

SCREENSHOT AND PRINT all outputs.

Solutions

Expert Solution

/*
* Java test program that demonstrates the given java statements in the below java class program.
* */
//ArrayLoop.java
import java.util.Arrays;
public class ArrayLoop
{
   public static void main(String[] args)
   {
       /*Create an array of integer type of size,8*/
       int[] myAddresses = new int[8];
       /*Loop over the array ,myAddresses that
       * stores the valuse of 2 to raise to power of i
       * at the index, i value of myAddresses*/
       for (int i = 0; i < myAddresses.length; i++)
       {
           myAddresses[i]=(int) Math.pow(2.0, i);
       }
       System.out.println("Arrays.toString() to print the myAddresses array");
       //print the myAddresses using Arrays.toString method
       System.out.println(Arrays.toString(myAddresses));
       System.out.println("printing the myAddresses in REVERSE order");
       //print the myAddresses to the console in reverse order
       for (int i = myAddresses.length-1;i>=0; i--)
       {
           System.out.print(myAddresses[i]+" ");
       }
      
       String myName = "Hughes";
       //print the size of the myName string object
       System.out.println("Length of the myName is "+myName.length());
      
       System.out.println("Printing the values in myName string ");
       System.out.println("each character one on a line");
       //print the myName letters each letter one at time
       for (int i = 0; i < myName.length(); i++)
       {
           System.out.println(myName.charAt(i));
       }                               
   }
}

Sample Output:


Related Solutions

Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
Step 1: Create a new Java project in NetBeans called “Wedding1” Step 2: Use appropriate data...
Step 1: Create a new Java project in NetBeans called “Wedding1” Step 2: Use appropriate data types to store the following information: The names of the bride and groom The total number of guests at the wedding The square footage of the location (must be accurate to 0.1 square feet). The names of each song in the DJ's playlist. You should use an ArrayList of Strings to store this, and the user should be able to enter as many song...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the class name YourlastnameLab7 with your actual last name. Create a Java class file for a Polygon class. Implement the Polygon class. Add a private instance variable representing the number of sides in the polygon. Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error...
IN java Create a New Java Project called LastNameDuplicate. //Given an array of N elements with...
IN java Create a New Java Project called LastNameDuplicate. //Given an array of N elements with each element between 1 and N, write a program to determine whether there are any duplicates. //You must prompt the user for the array elements. //Display the contents of the array, along with the values that are duplicated and how many times they appeared in the array. //NOTE: N should be at least 15. Input Validation: Verify that each element entered has a value...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
this a continuation of my previous question. answer with Java programming language and Netbeans idk 1,...
this a continuation of my previous question. answer with Java programming language and Netbeans idk 1, 2, 3, 4) CODE class Device { private String serialNumber, color, manufacturer; private double outputPower; public Device () { serialNumber = ""; color = ""; manufacturer = ""; outputPower = 0.0; } public Device(String serialNumber, String color, String manufacturer, double outputPower) { this.serialNumber = serialNumber; this.color = color; this.manufacturer = manufacturer; this.outputPower = outputPower; } public String getSerialNumber() { return serialNumber; } public void...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4 grocery stores. Each store has 3 departments where product presentation affects sales (produce, meat, frozen). Every so often a department in a store gets a bonus for doing a really good job. You need to create a program that keeps a table of bonuses in the system for departments. Create a program that has a two dimensional array for these bonuses. The stores can...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT