0

Just wondering, is it not allowed to use Starts/EndsWith functions with Scanner? I'm trying to make a simple program where some elements from the set of array that I will provide will be printed out using those functions. But obviously there is an error that I don't know where it is. Please help

import java.util.Scanner;

public class test {
    public static void main (String[] args)
{
    Scanner input = new Scanner(System.in);
    String[] animals = new String[5];

System.out.println("Enter animal type");
    for (String j : animals){
        if (j.startsWith("do"))
            System.out.println(j);

    }

}
}
denmark16
  • 29
  • 7
  • 1
    You are using startsWith on a string, not a scanner. Also, you never receive input to enter animals into the array, so none of your strings start with "do" and nothing is printed. Remove the if statement and `null` will be printed 5 times. – OneCricketeer Dec 16 '15 at 12:23
  • also if you want to check startWith condition add some value to the array . – soorapadman Dec 16 '15 at 12:26

0 Answers0