0

What is wrong in this small java code?

https://code.sololearn.com/c7yzNOkvL0J0/?ref=app

4th Jun 2020, 5:52 AM
Harsh Vyas
Harsh Vyas - avatar
5 Answers
+ 1
you can see illegal characters if you open your code on web browser version of Sololearn 'playground' code editor (on desktop), there are pink places. I remove it and add one semicolon: import java.util.*; class CalculateBill { double billpay; void Bill(long units) { if (units < 100) billpay = units * 1.20; else if (units <= 300) billpay = 100 * 1.20 + (units - 100) * 2; else if (units > 300) billpay = 100 * 1.20 + 200 * 2 + (units - 300) * 3; //semicolon ; } } class ComputeElectricityBill extends CalculateBill { public static void main(String args[]) { long units; Scanner sc = new Scanner(System.in); System.out.println("enter number of units"); units = sc.nextLong(); ComputeElectricityBill b = new ComputeElectricityBill(); b.Bill(units); System.out.println("Bill to pay : " + b.billpay); } }
4th Jun 2020, 7:32 AM
zemiak
+ 2
Sometimes, usually when copying and pasting code to the playground, invisible characters will also be copied and pasted. You need to remove them. Just go through the code and remove all whitespace between lines and add it back while reformatting your code and you'll take care of the issue. Also you're missing a semicolon in the last line of your Bill method.
4th Jun 2020, 6:12 AM
ChaoticDawg
ChaoticDawg - avatar
0
Where is that?
4th Jun 2020, 6:06 AM
Harsh Vyas
Harsh Vyas - avatar
0
Thnkuu so much man zemiak
4th Jun 2020, 7:36 AM
Harsh Vyas
Harsh Vyas - avatar