Computer Science, asked by chetan1580, 10 months ago

write Java program to accept your name and find it's length

Answers

Answered by Aneelmalhi
0

Find Length of String

To find the length of the string in Java Programming, you have to ask to the user to enter the string and then find the length of that string using the method length() and display the length value of the string on the output screen as shown in the following program.

Java Programming Code to Find Length of String

Following Java Program ask to the user to enter a string to find its length using the length() method, then display the result on the screen:

/* Java Program Example - Find Length of String */ import java.util.Scanner; public class JavaProgram { public static void main(String args[]) { String str; int len; Scanner scan = new Scanner(System.in); System.out.print("Enter Your Name : "); str = scan.nextLine(); len = str.length(); System.out.print("Length of Entered String is " + len); } }

Answered by siddhartharao77
3

Sample Program to accept name and find length:

import java.util.*;

class brainly

{

public static void main(String args[])

{

String s;

int len;

System.out.print("Enter a string: ");

Scanner demo = new Scanner(System.in);

s = demo.nextLine();

len = s.length();

System.out.println("Length of the string is:" +len);

}

}

Output:

Enter a string: Siddhartha

Length of the string is: 10

Hope it helps!


siddhartharao77: Mark as brainliest
Similar questions