I just started working with arrays.My code is supposed to keep asking for the user to enter words/alphabets.However,if the words entered are similar for 2 consecutive entries,the program should display a message as shown below.The following was my hypothesis to compare 2 consecutive string elements.However,my program does't work.
import java.util.*;
public class StringArrays {
public static void main(String[]args)
{
String[] list=new String[50];
for( int i=0;i<50;i++)
{
Scanner a=new Scanner(System.in);
System.out.println("Enter something: ");
list[i]=a.next();
if(list[i]==list[i+1])
{
System.out.println("Stop!");
}
else
{
System.out.println("Smart!Continue..");
}
}
}
}
I'm just wondering what's the correct way to inspect 2 consecutive elements of a string array. Thanks for all your help :)