Reputation: 77
I have to get my method to read if the string has spaces and if it does it goes to the next step which is to see if the string has letters or numbers 1 through 5 in the string.
Here is what is stated in the directions: This method should examine its argument to see if it has a space in positions 5, 11, 17, 23 and so on, and if it consists of letters and the digits 1 though 5 in all other positions. If this is the case it should return true, otherwise return false.
This is the error I'm getting:
Enc1.java:41: error: no suitable method found for length(int)
if(s.indexOf(s.length(i)) == -1 || i > 5 || i < 1)
^
method CharSequence.length() is not applicable
(actual and formal argument lists differ in length)
method String.length() is not applicable
(actual and formal argument lists differ in length)
Here is the code:
import java.util.Scanner;
public class Enc1
{
public static void main(String[] args)
{
Scanner stdin = new Scanner(System.in);
String c1 = args[0];
System.out.println("Please insert a word: ");
c1 = stdin.next();
isCoded(c1);
} // end main
private static final String CODE1 = "HTNZUL5m3lDQchenpIuORws1jPgVtzKWbfBxXSArdayCJkvqGiF2YoM4E" ;
private static final String PLAIN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,.;:" ;
public static String encode(String message)
{
System.out.println("encode called");
return message;
} // end encode
public static String decode(String codedMessage)
{
System.out.println("decode called");
return codedMessage;
} // end decode
public static boolean isCoded(String s)
{
for( int i = 0; i < s.length(); ++i)
{
if( i % 6 == 5 && s.charAt(i) != ' ')
return false;
if(s.indexOf(s.length(i)) == -1 || i > 5 || i < 1)
return false;
}
} // end isCoded
} // end Enc1
Upvotes: 0
Views: 1323
Reputation: 285405
The error message is telling you exactly what's wrong -- the length method does not take a parameter -- so do the obvious solution and fix it: get rid of the erroneous call.
Change
if(s.indexOf(s.length(i)) == -1 || i > 5 || i < 1)
to
if(s.indexOf(s.charAt(i)) == -1 || i > 5 || i < 1)
Upvotes: 2