+ 2
Hi, I need help, I keep getting errors, please help me find errors đ
6 Answers
+ 3
Janna Ariella Tabilog ,
This is my take on your code, this code might help you
int rn =
(grade >= 1.00 && grade <= 2.75) ? 1 :
(grade >= 2.76 && grade <= 3.99) ? 2 :
(grade >= 4.00 && grade <= 5.99) ? 3 : 0;
https://code.sololearn.com/c8Bdp3Qif2m9
+ 4
static Scanner sc = new Scanner (System.in);
here you are declaring it in method. static variables can only be declared class level. so remove static or declare outside methods.
double grade = sc.nextDouble(); // switch case values must be integral type so use integer input..
replace with these lines :
Scanner sc = new Scanner (System.in);
int grade = sc.nextInt();
+ 2
SoloProg, Thank you! đ«¶
+ 1
changed it now, it suddenly always answers on default :')
+ 1
Janna
What does ? : 1 means solo learn never taught me that please your valuable reply is appreciated
+ 1
Rapheal Oluwabukola ,
this is the explaniation of your question
Use of the Question mark colon Operator in java
The question mark and the colon operators, when used together, can be known as a ternary operator.
It consists of three operands, and is therefore also known as a short-hand if...else operator. The only advantage it has that unlike multiple lines of code written in if...else statement, ternary operator can be written in a single line of code.
The Question mark and colon operator is made up of three segments. The first segment is a boolean expression that returns either true or false. The second and third segments are the values that are assigned if the expression returns the boolean value true or false respectively. The second and third segments are separated by the use of a : sign.
The question mark operator has the syntax as follows:
var = condition ? value_if_true : value_if_false