Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Tugas3 {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int soal = 0;
- System.out.print("Soal = ");
- soal = Integer.parseInt(br.readLine());
- switch(soal) {
- case 1 :
- soal1();
- break;
- case 2 :
- soal2();
- break;
- case 3 :
- soal3();
- break;
- case 4 :
- soal4();
- break;
- case 5 :
- soal5();
- break;
- case 6 :
- soal6();
- break;
- case 7 :
- soal7();
- break;
- case 8 :
- soal8();
- break;
- case 9 :
- soal9();
- break;
- case 10 :
- soal10();
- break;
- case 11 :
- soal11();
- break;
- case 12 :
- soal12();
- break;
- case 13 :
- soal13();
- break;
- case 14 :
- soal14();
- break;
- case 15 :
- soal15();
- break;
- case 16 :
- soal16();
- break;
- case 17 :
- soal17();
- break;
- case 18 :
- soal18();
- break;
- case 19 :
- soal19();
- break;
- case 20 :
- soal20();
- break;
- case 21 :
- soal21();
- break;
- case 22 :
- soal22();
- break;
- case 23 :
- soal23();
- break;
- case 24 :
- soal24();
- break;
- case 25 :
- soal25();
- break;
- case 26 :
- soal26();
- break;
- case 27 :
- soal27();
- break;
- case 28 :
- soal28();
- break;
- case 29 :
- soal29();
- break;
- case 30 :
- soal30();
- break;
- case 31 :
- soal31();
- break;
- case 32 :
- soal32();
- break;
- case 33 :
- soal33();
- break;
- case 34 :
- soal34();
- break;
- case 35 :
- soal35();
- break;
- case 36 :
- soal36();
- break;
- case 37 :
- soal37();
- break;
- case 38 :
- soal38();
- break;
- case 39 :
- soal39();
- break;
- case 40 :
- soal40();
- break;
- case 41 :
- soal41();
- break;
- case 42 :
- soal42();
- break;
- case 43 :
- soal43();
- break;
- case 44 :
- soal44();
- break;
- case 45 :
- soal45();
- break;
- case 46 :
- soal46();
- break;
- case 47 :
- soal47();
- break;
- case 48 :
- soal48();
- break;
- case 49:
- soal49();
- break;
- }
- }
- public static void soal1() {
- int i = 1;
- do {
- System.out.println("Hello World");
- i++;
- } while (i <= 100);
- }
- public static void soal2() {
- int i = 1;
- while (i <= 100) {
- System.out.println(i);
- i++;
- }
- }
- public static void soal3() {
- int i = 100;
- do {
- System.out.println(i);
- i--;
- } while (i > 0);
- }
- public static void soal4() {
- int i = 30;
- do {
- if (i % 2 != 0) {
- System.out.println(i);
- }
- i++;
- } while(i <= 120);
- }
- public static void soal5() {
- int i = 30;
- do {
- if (i % 2 == 0) {
- System.out.println(i);
- }
- i++;
- } while (i <= 120);
- }
- public static void soal6() {
- int i = 1;
- while (i <= 100) {
- if (i % 7 == 0) {
- System.out.println(i);
- }
- i++;
- }
- }
- public static void soal7() {
- for(int i = 1; i <= 500; i++) {
- if (i % 15 == 0) {
- System.out.println(i);
- }
- }
- }
- public static void soal8() throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int batas_bawah = 0, batas_atas = 0;
- System.out.print("Batas bawah = ");
- batas_bawah = Integer.parseInt(br.readLine());
- System.out.print("Batas atas = ");
- batas_atas = Integer.parseInt(br.readLine());
- while (batas_bawah <= batas_atas) {
- if (batas_bawah % 25 == 0) {
- System.out.println(batas_bawah);
- }
- batas_bawah++;
- }
- }
- public static void soal9() {
- char i = 'A';
- while (i <= 'Z') {
- System.out.println(i);
- i++;
- }
- }
- public static void soal10() {
- char i = 'Z';
- while (i >= 'A') {
- System.out.println(i);
- i--;
- }
- }
- public static void soal11() {
- for (int i = 1; i <= 5; i++) {
- System.out.print(i);
- if (i >= 1 && i < 5) {
- System.out.print(" dan ");
- }
- }
- }
- public static void soal12() {
- int jumlah = 0;
- for (int i = 1; i <= 10; i++) {
- jumlah += i;
- if (i == 10) {
- System.out.print(i + " = " + jumlah);
- }
- else {
- System.out.print(i + " + ");
- }
- }
- }
- public static void soal13() {
- int i = 1;
- int j = 1;
- while (j <= 8) {
- i *= 2;
- j++;
- System.out.print(i + " ");
- }
- }
- public static void soal14() {
- for (int i = 1; i <= 7; i++) {
- for (int j = 1; j <= i; j++) {
- System.out.print(i + " ");
- }
- }
- }
- public static void soal15() {
- for (int i = 7; i > 0; i--) {
- for (int j = 1; j <= i; j++) {
- System.out.print(i + " ");
- }
- }
- }
- public static void soal16() {
- for (int i = 1; i <= 6; i++) {
- for (int j = 1; j <= i; j++) {
- System.out.print(j + " ");
- }
- }
- }
- public static void soal17() {
- for (int i = 6; i > 0; i--) {
- for (int j = i ; j > 0 ; j--) {
- System.out.print(j + " ");
- }
- }
- }
- public static void soal18() {
- for (int i = 1; i <=6; i++) {
- for (int j = 1; j<=i; j++) {
- if (i % 2 == 0) {
- System.out.print(j + " ");
- }
- else {
- System.out.print(i + " ");
- }
- }
- }
- }
- public static void soal19() {
- for (int i = 1; i <= 6; i++) {
- for (int j = 1 ; j<=i; j++) {
- if (i % 2 == 0) {
- System.out.print(i + " ");
- }
- else {
- System.out.print(j + " ");
- }
- }
- }
- }
- public static void soal20() {
- for (int i = 6; i > 0; i--) {
- for (int j = i; j > 0; j--) {
- if (i % 2 == 0) {
- System.out.print(j+ " ");
- }
- else {
- System.out.print(i+ " ");
- }
- }
- }
- }
- public static void soal21() {
- for (int i = 6; i > 0; i--) {
- for (int j = 1 ; j <= i; j++) {
- if (i % 2 == 0) {
- System.out.print(i + " ");
- }
- else {
- System.out.print(j + " ");
- }
- }
- }
- }
- public static void soal22() {
- for (int i = 1 ; i <= 9; i++) {
- for (int j = 1 ; j <= i; j++) {
- if (i % 4 == 1 || i % 4 == 2) {
- System.out.print(i);
- }
- else {
- System.out.print(j);
- }
- }
- }
- }
- public static void soal23() {
- for (int i = 1; i <= 9 ; i++) {
- for(int j = 1; j <= i; j++) {
- if (i % 4 == 0 || i % 4 == 3) {
- System.out.print(i);
- }
- else {
- System.out.print(j);
- }
- }
- }
- }
- public static void soal24() {
- for (int i = 8 ; i > 0 ; i--) {
- for (int j = i ; j > 0 ; j--) {
- if (i % 4 == 3 || i % 4 == 0) {
- System.out.print(i);
- }
- else {
- System.out.print(j);
- }
- }
- }
- }
- public static void soal25() {
- for (int i = 8 ; i > 0 ; i--) {
- for (int j = i ; j > 0 ; j--) {
- if (i % 4 == 2 || i % 4 == 1) {
- System.out.print(i);
- }
- else{
- System.out.print(j);
- }
- }
- }
- }
- public static void soal26() {
- int awal = 1;
- for (int i = 0; i < 12; i++) {
- System.out.print(awal + " ");
- if (i % 2 == 0) {
- awal += 4;
- }
- else {
- awal -= 2;
- }
- }
- }
- public static void soal27() {
- int awal = 2;
- for (int i = 0; i < 10; i++) {
- System.out.print(awal + " ");
- if (i % 2 == 0) {
- awal += 10;
- }
- else {
- awal -= 5;
- }
- }
- }
- public static void soal28() {
- int awal = 5;
- for (int i = 0; i < 12; i++) {
- System.out.print(awal + " ");
- if (i % 2 == 0) {
- awal -= 3;
- }
- else {
- awal += 5;
- }
- }
- }
- public static void soal29() {
- int awal = 3, ratio = 1;
- for (int i = 0; i < 5; i++) {
- System.out.print(awal + " ");
- System.out.print(awal * 3 + " ");
- awal += ratio;
- ratio *= 3;
- }
- }
- public static void soal30() {
- int awal = 1;
- for (int i = 1; i < 14; i++) {
- System.out.print(awal + " ");
- if (i % 3 == 0) {
- awal += 3;
- }
- else if (i % 3 == 1) {
- awal += 1;
- }
- else {
- awal += 2;
- }
- }
- }
- public static void soal31() {
- int awal = 1;
- while (awal <= 512) {
- System.out.print(awal + " ");
- awal *= 2;
- }
- }
- public static void soal32() {
- int angka1 = 0, angka2 = 1, angka3 = 0;
- while (angka1 <= 34) {
- System.out.print(angka1 + " ");
- angka3 = angka1 + angka2;
- angka1 = angka2;
- angka2 = angka3;
- }
- }
- public static void soal33() {
- int angka1 = 0, angka2 = 1, angka3 = 0, i = 0;
- do {
- System.out.print(angka1 + " ");
- angka3 = angka1 + angka2;
- angka1 = angka2;
- angka2 = angka3;
- i++;
- } while(i < 10);
- }
- public static void soal34() {
- for (int i = 1; i <= 3; i++) {
- for (int j = 1; j <= 10; j++ ) {
- System.out.print("1" + " ");
- }
- System.out.println();
- }
- }
- public static void soal35() {
- for (int i = 1; i <= 3; i++) {
- for (int j = 1; j <= (i * 3); j++) {
- System.out.print("1" + " ");
- }
- System.out.println();
- }
- }
- public static void soal36() {
- int awal = 2;
- for (int i = 1; i <= 16; i++) {
- System.out.print(awal + " ");
- if (i % 2 == 0) {
- awal += 7;
- }
- else {
- awal -= 5;
- }
- }
- }
- public static void soal37() {
- for (int i = 1; i <= 18; i++) {
- if (i % 3 == 0) {
- System.out.print("1" + " ");
- }
- else if (i % 3 == 1) {
- System.out.print("0" + " ");
- }
- else {
- System.out.print("*" + " ");
- }
- }
- }
- public static void soal38() {
- for (int i = 1; i <= 1000000; i *= 10) {
- System.out.print(i + " ");
- }
- }
- public static void soal39() {
- for (int i = 1; i <= 3; i++) {
- for (int j = 1; j <= 7; j++) {
- System.out.print("*" + " ");
- }
- System.out.println();
- }
- }
- public static void soal40() {
- for (int i = 1; i <= 3; i++) {
- for (int j = 1; j <= 5; j++) {
- System.out.print("1" + " ");
- }
- System.out.println();
- }
- }
- public static void soal41() {
- for (int i = 1; i <= 4; i++) {
- for (int j = 1; j <= 7; j++) {
- System.out.print(i + " ");
- }
- System.out.println();
- }
- }
- public static void soal42() {
- for (int i = 1; i <= 5; i++) {
- for (int j = 1; j <= 7; j++) {
- System.out.print(j + " ");
- }
- System.out.println();
- }
- }
- public static void soal43() {
- for (int i = 1; i <= 7; i++) {
- for (int j = 1; j <= i; j++) {
- System.out.print(i + " ");
- }
- System.out.println();
- }
- }
- public static void soal44() {
- for (int i = 1; i <= 7; i++) {
- for (int j = 1; j <= i; j++) {
- System.out.print(j + " ");
- }
- System.out.println();
- }
- }
- public static void soal45() {
- for (int i = 1; i <= 3; i++) {
- for (int j = 1; j <= 7; j++) {
- System.out.print(i + "." + j + " ");
- }
- System.out.println();
- }
- }
- public static void soal46() {
- for (int i = 1; i <= 5; i++) {
- for (int j = 1; j <= i; j++) {
- System.out.print("*" + " ");
- }
- System.out.println();
- }
- }
- public static void soal47() {
- for (int i = 5; i >= 1; i--) {
- for (int j = 1; j <= i; j++) {
- System.out.print("*" + " ");
- }
- System.out.println();
- }
- }
- public static void soal48(){
- for (int i = 1; i <= 4; i++) {
- for (int j = 4; j > i; j--) {
- System.out.print(" ");
- }
- for (int k = 1; k < i*2; k++) {
- System.out.print("*" + " ");
- }
- System.out.println();
- }
- }
- public static void soal49() {
- for (int i = 1; i <= 4; i++) {
- for (int j = 1; j <= i+2; j++) {
- System.out.print("*" + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment