I'm sorry to bother you all with this thing, because in reality, it's a completely useless program, but completing it will get me that much closer to a grasp of Java. I tried searching for the answer first, but I couldn't find the information I need.
To be honest, I'm not sure if what I'm trying to do is possible, but here goes; I'm trying to make it so that a specific user input (in this case, "Life is like a") causes a random number between 0 and 3 to be generated, and that number to correlate with some Strings in an array, so it will randomly print one of the messages included in the array. Eclipse doesn't show any actual errors in my code, but even if the code is sound, it's still not working the way I intended. When you run the program and input "Life is like a", it doesn't output anything.
I know my code is probably sloppy and weird...I'm just starting out...
Code:
import java.util.Random;
import java.util.Scanner;
class Gumpy {
public static void main(String args[]){
Random rand = new Random();
Scanner input = new Scanner(System.in);
String gump = "Life is like a";
String life[]={" box of chocolates."," beanstalk, isn't it?"," pig's ***; salty and full of wonder."," sick game where nobody wins."};
int option = rand.nextInt(4);
if(input.nextLine() == gump){
System.out.println(life[option]);
}
}
}