Created
September 18, 2023 09:42
-
-
Save ardzz/b73af031ca69c65defe3ca486a748fad to your computer and use it in GitHub Desktop.
Challenge 3 & 4 (Naufal Reky Ardhana - 4.33.22.0.21)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:minggu_2/minggu_2.dart' as minggu_2; | |
void main(List<String> arguments) { | |
int? nilai = inputNilai(); | |
if (nilai != null) { | |
print("output menggunakan if else"); | |
if (nilai >= 91 && nilai <= 100) { | |
print('Sangat Baik'); | |
} else if (nilai >= 81 && nilai <= 90) { | |
print('Baik'); | |
} else if (nilai >= 71 && nilai <= 80) { | |
print('Cukup'); | |
} else if (nilai >= 61 && nilai <= 70) { | |
print('Kurang'); | |
} else if (nilai >= 0 && nilai <= 60) { | |
print('Sangat Kurang'); | |
} else { | |
print('Nilai Invalid'); | |
} | |
print("output menggunakan ternary operator"); | |
nilai >= 91 && nilai <= 100 | |
? print('Sangat Baik') | |
: nilai >= 81 && nilai <= 90 | |
? print('Baik') | |
: nilai >= 71 && nilai <= 80 | |
? print('Cukup') | |
: nilai >= 61 && nilai <= 70 | |
? print('Kurang') | |
: nilai >= 0 && nilai <= 60 | |
? print('Sangat Kurang') | |
: print('Nilai Invalid'); | |
} else { | |
print('Nilai Invalid'); | |
} | |
} | |
int? inputNilai() { | |
stdout.write('Masukkan nilai:'); | |
String? input = stdin.readLineSync(); | |
if (input != null) { | |
int? nilai = int.tryParse(input); | |
return nilai; | |
} else { | |
return null; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
void main(){ | |
/* | |
# A : Sangat Enak | |
# B : Enak | |
# C : Cukup | |
# D : Kurang | |
# E : Belajar Dulu | |
# Selain itu : Nilai Invalid | |
* */ | |
String? nilai = inputNilai(); | |
if (nilai != null) { | |
switch (nilai) { | |
case 'A': | |
print('Sangat Enak'); | |
break; | |
case 'B': | |
print('Enak'); | |
break; | |
case 'C': | |
print('Cukup'); | |
break; | |
case 'D': | |
print('Kurang'); | |
break; | |
case 'E': | |
print('Belajar Dulu'); | |
break; | |
default: | |
print('Nilai Invalid'); | |
} | |
} else { | |
print(nilai); | |
} | |
} | |
String? inputNilai() { | |
stdout.write('Masukkan nilai:'); | |
String? input = stdin.readLineSync(); | |
return input; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
void main(){ | |
print("n=2"); | |
pyramid(2); | |
print("n=5"); | |
pyramid(5); | |
} | |
void pyramid(int n){ | |
for(int i = 1; i <= n; i++){ | |
for(int j = 1; j <= i; j++){ | |
stdout.write("*"); | |
} | |
stdout.write("\n"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
void reversePyramid(int n){ | |
for(int i = n; i >= 1; i--){ | |
for(int j = 1; j <= i; j++){ | |
stdout.write("*"); | |
} | |
stdout.write("\n"); | |
} | |
} | |
void main(){ | |
print("n=2"); | |
reversePyramid(2); | |
print("n=5"); | |
reversePyramid(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment