The Programm is supposed to let me enter a value a and a string. While it lets me input he integer when it comes to the string, it prints the question but does not let me enter anything.
import java.util.Scanner;
public class PrSumN {
public static void main(String args[]) {
System.out.println("Enter a value");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int sum = 0;
int pr = 1;
System.out.println("Do you want the sum of the numbers or the products of the numbers?");
String answer = sc.nextLine();
//Itdoesnotletmeinputmystringatthispoint
if (answer == "sum") {
sum(a, sum);
} else {
product(a, pr);
}
}
public static void sum(int a, int sum) {
for (int i = 0; i < a; i++) {
sum = sum + (a - i);
}
System.out.println("The sum of the numbers is " + sum);
}
public static void product(int a, int pr) {
for (int i = 0; i < a; i++) {
pr = pr * (a - i);
}
}
}