Question: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then, create

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then, create a new Java application called "StringLength" (without the quotation marks) that requests a String from the user at the command line and finds its length. Your program should output: "Your string has a length of X characters." where X is the String's length. Allow for the String to be one or more words of input. Be sure to use the suitable method for determining the length of the String.

I have the below code but it is only giving me the output that "Your string has a length of x characters". it is not outputting that Hello, my name is John Smith.

package stringlength;

import java.util.Scanner;

public class StringLength { public static void main(String[] args) { if(args.length > -1) { String input = args[0]; int length = input.length(); // using length() method in String class System.out.println("Your string has a length of "+length+" characters."); System.out.println("Your string has a length of "+length+" characters."); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!