0

why it is showing <identifier expected>?

package com.company; import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here int basic,allow; char grade; double hra,da,pf,totalSalary; Scanner s=new.Scanner(System.in); basic=s.nextInt(); grade=s.next(); hra=(20/100)*basic; da=(50/100)*basic; pf=(11/100)*basic; if(grade=='A'){ allow=1700; elif(grade=='B'){ allow=1500); else: allow=1300; } } System.out.println("totalSalary="+(basic+hra+da+allow-pf)); } } error: error: identifier expected Scanner s=new.Scanner(System.in); ^ Main.java:29: error: illegal start of expression else: ^ Main.java:29: error: 'else' without 'if' else: ^ Main.java:33: error: expected System.out.println("totalSalary="+(basic+hra+da+allow-pf)); ^ Main.java:33: error: illegal start of type System.out.println("totalSalary="+(basic+hra+da+allow-pf)); ^ Main.java:35: error: class, interface, or enum expected } ^ 6 errors

24th Apr 2022, 6:11 AM
Durga M
Durga M - avatar
3 Answers
+ 4
new.Scanner should be new Scanner, no dot. In java, elif and else: don't exist.
24th Apr 2022, 7:21 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
// do not use package in SoloLearn //package com.company; ,,, //after new is not dot // Scanner s = new.Scanner(System.in); Scanner s = new Scanner(System.in); .,,. //read char instead of String // grade=s.next(); grade=s.next().charAt(0); .., // usually there are parenteses this way if (grade=='A') { allow=1700; } else if (grade=='B') { allow=1500; } else { allow=1300; } ..,
25th Apr 2022, 12:02 AM
zemiak
+ 2
Scanner s = new Scanner(System.in); if(grade == 'A'){ allow = 1700; else if(grade == 'B'){ allow = 1500; }else{ allow = 1300; } I guess you confused Python with Java. ;)
24th Apr 2022, 8:16 AM
Denise Roßberg
Denise Roßberg - avatar