package com.codegym.task.task07.task0703;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.lang.String;
/*
Lonely arrays interact
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
Scanner scanner = new Scanner(System.in);
String[] name = new String[10];
int[] number = new int[10];
for (int i = 0; i < name.length; i++){
name[i] = scanner.nextLine();
}
for (int i = 0; i < number.length; i++){
String x = name[i];
number[i] = x.length;
System.out.println(number[i]);
}
}
}
it's giving an error in x.length. Help me out plzzzzz
Archived
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Jaisingh
4 October 2018, 08:47
better go with length() for composite data type(Strings)..!!
0
Kishan Singh
4 October 2018, 07:35
length method without brackets is used to find out the length of an array. In case of String length length() method is used. So use x.length() in place of x.length.
0
Ankush Rajput
4 October 2018, 03:22
it should be x.length() and not x.length.
length is a function in string class and not a field.
x.length will work in case x is an array. For string, use x.length().
+1