0

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

first input preview: first input preview:

now , my second input: second input preview

now, I am attempting to end my input by typing compute , which is i don't know how. pardon compute error preview 1

in case you are intereseted with the errors, here they are: enter image description here

I really don't know the logic for it. i just tried

jerome_mjt
  • 280
  • 3
  • 12

0 Answers0