Answer :

Answer:

import java.util.Scanner;

public class StringSize {

  public static void main (String [] args) {

     Scanner scnr = new Scanner(System.in);

     String userInput;

     int stringSize;

     userInput = scnr.nextLine();

     

     /* Your solution goes here  */

     

     stringSize = userInput.length();

     

     System.out.println("Size of userInput: " + stringSize);

     return;

  }

}

Explanation:

stringSize = userInput.length();  //  userInput.length() will get the length of the string and  put in stringSize

The C code that solves this question is:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main(){

char userInput[100];

scanf("%s\n", &userInput);

stringSize = strlen(userInput);

return 0;

}

----------------------

  • I am going to present a C code for this problem.
  • The first part is including the libraries(.h) and the main function.
  • The first part is declaring userInput, which I am going to declare as a string of at most 100 characters, thus char userInput[100].
  • The, it reads the userInput, with the scanf.
  • Doing stringSize = strlen(userInput), it assigns the size.

A similar problem is given at https://brainly.com/question/13486181

Other Questions