Question: Java How to fix the output? How to get the right length of the String? Code: import java.util.Arrays; public class PeelOnion { public static void
Java
How to fix the output? How to get the right length of the String?
Code:
import java.util.Arrays;
public class PeelOnion { public static void main(String[] args) throws Exception{ Onion[] myStuff = new Onion[5]; myStuff[0] = new Onion( "There should be some sort of text here..." ); myStuff[1] = new Onion( "Hello! How are you?" ); myStuff[2] = new Onion( "My name is " ); myStuff[3] = new Onion( ); myStuff[4] = new Onion( "It's a lovely day in the neighborhood." );
for( int h = 0; h
}
}
UML from the class Onion.java:
Expected Output:
Thank You
Onion Attributes private onion: String Contains a reference to a String object Operations public Onion() nicn Null constructor; creates a default String object reference for onion public Onion( layer: String ): Onion Accepts a String object reference; assigns to instance variable onion 8 public getlength( ): int Returns an integer representing the length of the String object referenced by instance variable onion Notes Standard naming is used for set and get methods General coding standard apply Expected Output from PeelOnion.java There should be some sort of text here... The String at subscript 0 is 41 characters long. Hello! How are you? The String at subscript 1 is 19 characters long. My name is The String at subscript 2 is 11 characters long This is a default message layer. The String at subscript 3 is 32 characters long. It's a lovely day in the neighborhood The String at subscript 4 is 38 characters long
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
