I'm coding a simple project but i face a very small problem here. To be honest I don't know the right logic for my problem
I have a while condition there so that it will not stop recieveing inputs. I want to stop the input just by typing 'compute' but it gives me errors because I really don't know how to insert that 'compute' thingy after that output of System.out.println(bla bla)
int discreteNum;
double prob;
boolean condition = true;
String forComput;
Scanner input = new Scanner(System.in);
Scanner str = new Scanner(System.in);
//These are just outputs, they're harmless
System.out.println("Mean of Discrete Random Variable \n");
System.out.print("Instructions:\n");
System.out.print("Please enter a discrete random variable with its
probability\n type 'compute' for the expected value\n");
while(condition = true ){
discreteNum = input.nextInt();
prob = input.nextDouble();
System.out.println("( " + discreteNum + "," + prob + " )");
}
//This code below, I just put it here.
//It's just my insight. I tried it but it did not work.
//It's worthy to be deleted here but I just want to show you
forComput = str.nextLine();
if(forComput == "compute"){
condition = false;
System.out.println("End!");
}
This is how my code works
now, I am attempting to end my input by typing compute , which is i don't know how. pardon
in case you are intereseted with the errors, here they are:
I really don't know the logic for it. i just tried