0
What is wrong in this small java code?
5 odpowiedzi
+ 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);
}
}
+ 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.
0
Where is that?
0
Thnkuu so much man zemiak