Skip to content

Commit 47d4d04

Browse files
committed
Basic:- Solution to find Sum of Even Numbers
1 parent cfb40c4 commit 47d4d04

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package Scaler.Assignments;
2+
3+
import java.util.Scanner;
4+
5+
public class ElectricityBill {
6+
public static void main(String[] args) {
7+
Scanner scanner = new Scanner(System.in);
8+
9+
int units = scanner.nextInt();
10+
11+
int billValue = 0;
12+
13+
while (units > 0){
14+
15+
if (units <= 50){
16+
billValue = calculateUnitRates(units);
17+
units -= 50;
18+
}else if(units > 50 && units <= 150){
19+
20+
}
21+
}
22+
}
23+
24+
static int calculateUnitRates(int unit){
25+
int bill = 0;
26+
if (unit > 250){
27+
bill *= 1.50;
28+
}else if(unit > 150 && unit <= 250){
29+
bill *= 1.20;
30+
}else if(unit > 50 && unit <= 150){
31+
bill *= 0.75;
32+
}else{
33+
bill *= 0.50;
34+
}
35+
36+
return bill;
37+
}
38+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Scaler.Assignments;
2+
3+
public class SumOfEvens {
4+
public static void main(String[] args) {
5+
6+
int sum = 0;
7+
8+
for(int i = 0; i <= 100; i++){
9+
if(i % 2 == 0){
10+
sum = sum + i;
11+
}
12+
}
13+
System.out.println(sum);
14+
}
15+
}

0 commit comments

Comments
 (0)