To achieve the desired functionality, you can use a while loop that keeps prompting the user for a choice until they enter 0. Inside the loop, based on the user's choice, you can handle the options 1 and 2 separately. Here's an updated version of your code to implement this logic:
```java
import java.io.*;
public class p2 {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int choice = -1;
while (choice != 0) {
System.out.println("0-Exit");
System.out.println("1-Compute the sum of some numbers");
System.out.println("2-Compute the product of some numbers");
String inputString = stdin.readLine();
choice = Integer.parseInt(inputString);
switch (choice) {
case 0:
System.out.println("Bye Bye");
break;
case 1:
computeSum();
break;
case 2:
computeProduct();
break;
default:
System.out.println("Invalid Selection");
break;
}
}
}
private static void computeSum() throws IOException {
System.out.println("How many numbers to add?");
int count = Integer.parseInt(stdin.readLine());
int sum = 0;
System.out.println("Please enter the numbers one by one:");
for (int i = 0; i < count; i++) {
sum += Integer.parseInt(stdin.readLine());
}
System.out.println("The sum is: " + sum);
}
private static void computeProduct() throws IOException {
System.out.println("Please enter the numbers:");
int product = 1;
int num;
while ((num = Integer.parseInt(stdin.readLine())) != 1) {
product *= num;
}
System.out.println("The product is: " + product);
}
}
```
Now when the user selects option 1, they will be asked to enter the number of numbers they want to add and then prompted to enter each number. The program will then calculate and display the sum.
Similarly, when the user selects option 2, they can enter multiple numbers until they enter 1, and the program will calculate and display the product. After each calculation, the menu will be displayed again to choose from.