Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write another short program that performs the following steps. i.Create a string

ID: 3685922 • Letter: W

Question

Write another short program that performs the following steps. i.Create a string variable callcd myString with 50 characters reserved for its size ii.Write a function callcd readString that has one parameter to pass the string. The function simply prompts the user to enter his or her name and stores it in the string. iii.Use the strlen function to determine the actual length of the name entered? iiii. Back in the main function after calling readString. output the string to the terminal by printing the following "You entered as your name. Your name is characters long." replacing the name from myString and the value from the strlen function. v.Can you enter a first and last name with a space between it with this program? vi.If not, how would you correct it?

Explanation / Answer

import java.util.*;
import java.io.*;
import java.lang.String;

public class Program
{
public static void main(String[] input)
{

       int MAX=50;
       int len;
  
  
String mystring ;
       mystring=readstring();
       len=mystring.length();
       System.out.println("you entered :"+mystring);
       System.out.println("you name length is:"+len);
      
      
  

          
}
   public static String readstring()
   {
       int size=50;
   String name;
   Scanner scan = new Scanner(System.in);
   System.out.println("enter your name");
   name=scan.nextLine();
   System.out.println("the name is"+name);
   return name;  
   }
}

nextLine reads strings with spaces also.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote