A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

How to get length of the string in java?
Q:

How to get length of the string in java?

0

How to get length of the string in java?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Given (we are reading it by the user) a string and we have to find its length using Java program.

To get the length of the string, we are using length() method of string class.

import java.util.Scanner;

public class ReturnLength
{
	public static void main(String[] args)
	{
		// create object of string and scanner class.
		String text;
		Scanner SC=new Scanner(System.in);

		// enter the string here.
		System.out.print("Enter the string : ");
		text=SC.nextLine();

		// find string length
		int length = text.length();
		// print length.
		System.out.println("Length of the given string " + text+ " is : " +length );
	}
}
First run:
Enter the string : Include Help
Length of the given string Include Help is : 12

Second run:
Enter the string : We are programmers.
Length of the given string We are programmers. is : 19

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now