enter image description hereVery simple problem but showing Runtime error on the site(beginner btw). Not so sure about the error, but i think the input part is incorrect(getting multiple strings from input). Is there any other ways to get input on String array? if there is, please let me know.
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.base/java.util.Scanner.nextLine(Scanner.java:1651)
at ExcellentResult.main(ExcellentResult.java:14)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at _$SandboxExecutor.main(_$SandboxExecutor.java:38)`package examples0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int salary = scanner.nextInt();
String[] tabs = new String[n];
int i;
for(i=0; i<n; i++) tabs[i] = scanner.nextLine();
for(i=0; i<n; i++){
switch (tabs[i]) {
case "Facebook":
salary-=150;
break;
case "Instagram":
salary-=100;
break;
case "Reddit":
salary-=50;
break;
}
}
if(salary>0){
System.out.println(salary);
}
else{
System.out.println("You have lost your salary.");
}
}