DerioFT

1-49

Nov 15th, 2023 (edited)
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.27 KB | Source Code | 0 0
  1. import java.io.*;
  2. public class Tugas3 {
  3.  
  4.     public static void main(String[] args) throws IOException {
  5.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  6.         int soal = 0;
  7.        
  8.         System.out.print("Soal = ");
  9.         soal = Integer.parseInt(br.readLine());
  10.        
  11.         switch(soal) {
  12.             case 1 :
  13.                 soal1();
  14.                 break;
  15.                
  16.             case 2 :
  17.                 soal2();
  18.                 break;
  19.                
  20.             case 3 :
  21.                 soal3();
  22.                 break;
  23.                
  24.             case 4 :
  25.                 soal4();
  26.                 break;
  27.                
  28.             case 5 :
  29.                 soal5();
  30.                 break;
  31.                
  32.             case 6 :
  33.                 soal6();
  34.                 break;
  35.                
  36.             case 7 :
  37.                 soal7();
  38.                 break;
  39.                
  40.             case 8 :
  41.                 soal8();
  42.                 break;
  43.                
  44.             case 9 :
  45.                 soal9();
  46.                 break;
  47.                
  48.             case 10 :
  49.                 soal10();
  50.                 break;
  51.                
  52.             case 11 :
  53.                 soal11();
  54.                 break;
  55.                
  56.             case 12 :
  57.                 soal12();
  58.                 break;
  59.                
  60.             case 13 :
  61.                 soal13();
  62.                 break;
  63.                
  64.             case 14 :
  65.                 soal14();
  66.                 break;
  67.                
  68.             case 15 :
  69.                 soal15();
  70.                 break;
  71.                
  72.             case 16 :
  73.                 soal16();
  74.                 break;
  75.                
  76.             case 17 :
  77.                 soal17();
  78.                 break;
  79.                
  80.             case 18 :
  81.                 soal18();
  82.                 break;
  83.                
  84.             case 19 :
  85.                 soal19();
  86.                 break;
  87.                
  88.             case 20 :
  89.                 soal20();
  90.                 break;
  91.                
  92.             case 21 :
  93.                 soal21();
  94.                 break;
  95.                
  96.             case 22 :
  97.                 soal22();
  98.                 break;
  99.  
  100.             case 23 :
  101.                 soal23();
  102.                 break;
  103.                
  104.             case 24 :
  105.                 soal24();
  106.                 break;
  107.                
  108.             case 25 :
  109.                 soal25();
  110.                 break;
  111.                
  112.             case 26 :
  113.                 soal26();
  114.                 break;
  115.                
  116.             case 27 :
  117.                 soal27();
  118.                 break;
  119.            
  120.             case 28 :
  121.                 soal28();
  122.                 break;
  123.            
  124.             case 29 :
  125.                 soal29();
  126.                 break;
  127.                
  128.             case 30 :
  129.                 soal30();
  130.                 break;
  131.                
  132.             case 31 :
  133.                 soal31();
  134.                 break;
  135.                
  136.             case 32 :
  137.                 soal32();
  138.                 break;
  139.            
  140.             case 33 :
  141.                 soal33();
  142.                 break;
  143.                
  144.             case 34 :
  145.                 soal34();
  146.                 break;
  147.                
  148.             case 35 :
  149.                 soal35();
  150.                 break;
  151.                
  152.             case 36 :
  153.                 soal36();
  154.                 break;
  155.                
  156.             case 37 :
  157.                 soal37();
  158.                 break;
  159.                
  160.             case 38 :
  161.                 soal38();
  162.                 break;
  163.                
  164.             case 39 :
  165.                 soal39();
  166.                 break;
  167.                        
  168.             case 40 :
  169.                 soal40();
  170.                 break;     
  171.            
  172.             case 41 :
  173.                 soal41();
  174.                 break;
  175.            
  176.             case 42 :
  177.                 soal42();
  178.                 break;
  179.            
  180.             case 43 :
  181.                 soal43();
  182.                 break;
  183.            
  184.             case 44 :
  185.                 soal44();
  186.                 break;
  187.            
  188.             case 45 :
  189.                 soal45();
  190.                 break;
  191.            
  192.             case 46 :
  193.                 soal46();
  194.                 break;
  195.            
  196.             case 47 :
  197.                 soal47();
  198.                 break;
  199.            
  200.             case 48 :
  201.                 soal48();
  202.                 break;
  203.                
  204.             case 49:
  205.                 soal49();
  206.                 break;
  207.         }
  208.  
  209.     }
  210.     public static void soal1() {
  211.        
  212.         int i = 1;
  213.        
  214.         do {
  215.             System.out.println("Hello World");
  216.             i++;
  217.         } while (i <= 100);
  218.     }
  219.    
  220.     public static void soal2() {
  221.        
  222.         int i = 1;
  223.        
  224.         while (i <= 100) {
  225.             System.out.println(i);
  226.             i++;
  227.         }
  228.     }
  229.    
  230.     public static void soal3() {
  231.        
  232.         int i = 100;
  233.        
  234.         do {
  235.             System.out.println(i);
  236.             i--;
  237.         } while (i > 0);
  238.     }
  239.    
  240.     public static void soal4() {
  241.         int i = 30;
  242.        
  243.         do {
  244.             if (i % 2 != 0) {
  245.                 System.out.println(i);
  246.             }
  247.             i++;
  248.         } while(i <= 120);
  249.     }
  250.    
  251.     public static void soal5() {
  252.        
  253.         int i = 30;
  254.        
  255.         do {
  256.             if (i % 2 == 0) {
  257.                 System.out.println(i);
  258.             }
  259.             i++;
  260.         } while (i <= 120);
  261.     }
  262.    
  263.     public static void soal6() {
  264.        
  265.         int i = 1;
  266.        
  267.         while (i <= 100) {
  268.            
  269.             if (i % 7 == 0) {
  270.                 System.out.println(i);
  271.             }
  272.             i++;
  273.         }
  274.     }
  275.    
  276.     public static void soal7() {
  277.        
  278.         for(int i = 1; i <= 500; i++) {
  279.             if (i % 15 == 0) {
  280.                 System.out.println(i);
  281.             }
  282.         }
  283.     }
  284.    
  285.     public static void soal8() throws IOException {
  286.        
  287.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  288.        
  289.         int batas_bawah = 0, batas_atas = 0;
  290.        
  291.         System.out.print("Batas bawah = ");
  292.         batas_bawah = Integer.parseInt(br.readLine());
  293.         System.out.print("Batas atas = ");
  294.         batas_atas = Integer.parseInt(br.readLine());
  295.        
  296.         while (batas_bawah <= batas_atas) {
  297.             if (batas_bawah % 25 == 0) {
  298.                 System.out.println(batas_bawah);
  299.             }
  300.             batas_bawah++;
  301.         }
  302.     }
  303.    
  304.     public static void soal9() {
  305.        
  306.         char i = 'A';
  307.        
  308.         while (i <= 'Z') {
  309.             System.out.println(i);
  310.             i++;
  311.         }
  312.     }
  313.    
  314.     public static void soal10() {
  315.        
  316.         char i = 'Z';
  317.        
  318.         while (i >= 'A') {
  319.             System.out.println(i);
  320.             i--;
  321.         }
  322.     }
  323.    
  324.     public static void soal11() {
  325.        
  326.         for (int i = 1; i <= 5; i++) {
  327.             System.out.print(i);
  328.            
  329.             if (i >= 1 && i < 5) {
  330.                 System.out.print(" dan ");
  331.             }
  332.         }
  333.     }
  334.    
  335.     public static void soal12() {
  336.        
  337.         int jumlah = 0;
  338.        
  339.         for (int i = 1; i <= 10; i++) {
  340.            
  341.             jumlah += i;
  342.            
  343.             if (i == 10) {
  344.                 System.out.print(i + " = " + jumlah);
  345.             }
  346.             else {
  347.                 System.out.print(i + " + ");
  348.             }
  349.         }
  350.     }
  351.    
  352.     public static void soal13() {
  353.        
  354.         int i = 1;
  355.         int j = 1;
  356.        
  357.         while (j <= 8) {
  358.             i *= 2;
  359.             j++;
  360.             System.out.print(i + " ");
  361.         }
  362.     }
  363.    
  364.     public static void soal14() {
  365.        
  366.         for (int i = 1; i <= 7; i++) {
  367.            
  368.             for (int j = 1; j <= i; j++) {
  369.                 System.out.print(i + " ");
  370.             }
  371.         }
  372.     }  
  373.    
  374.     public static void soal15() {
  375.        
  376.         for (int i = 7; i > 0; i--) {
  377.            
  378.             for (int j = 1; j <= i; j++) {
  379.                 System.out.print(i + " ");
  380.             }
  381.         }
  382.     }
  383.    
  384.     public static void soal16() {
  385.        
  386.         for (int i = 1; i <= 6; i++) {
  387.            
  388.             for (int j = 1; j <= i; j++) {
  389.                
  390.                 System.out.print(j + " ");
  391.             }
  392.         }
  393.     }
  394.    
  395.     public static void soal17() {
  396.        
  397.         for (int i = 6; i > 0; i--) {
  398.            
  399.             for (int j = i ; j > 0 ; j--) {
  400.                 System.out.print(j + " ");
  401.             }
  402.         }
  403.     }
  404.    
  405.     public static void soal18() {
  406.  
  407.         for (int i = 1; i <=6; i++) {
  408.            
  409.             for (int j = 1; j<=i; j++) {
  410.                
  411.                 if (i % 2 == 0) {
  412.                     System.out.print(j + " ");
  413.                 }
  414.                 else { 
  415.                     System.out.print(i + " ");
  416.                 }
  417.             }
  418.         }
  419.     }
  420.    
  421.     public static void soal19() {
  422.        
  423.         for (int i = 1; i <= 6; i++) {
  424.            
  425.             for (int j = 1 ; j<=i; j++) {
  426.                
  427.                 if (i % 2 == 0) {
  428.                     System.out.print(i + " ");
  429.                 }
  430.                 else {
  431.                     System.out.print(j + " ");
  432.                 }
  433.             }
  434.         }
  435.     }
  436.    
  437.     public static void soal20() {
  438.        
  439.         for (int i = 6; i > 0; i--) {
  440.            
  441.             for (int j = i; j > 0; j--) {
  442.                
  443.                 if (i % 2 == 0) {
  444.                     System.out.print(j+ " ");
  445.                 }
  446.                 else {
  447.                     System.out.print(i+ " ");
  448.                 }
  449.  
  450.             }
  451.         }
  452.     }
  453.    
  454.     public static void soal21() {
  455.        
  456.         for (int i = 6; i > 0; i--) {
  457.            
  458.             for (int j = 1 ; j <= i; j++) {
  459.                
  460.                 if (i % 2 == 0) {
  461.                     System.out.print(i + " ");
  462.                 }
  463.                 else {
  464.                     System.out.print(j + " ");
  465.                 }
  466.             }
  467.         }
  468.     }
  469.    
  470.     public static void soal22() {
  471.        
  472.         for (int i = 1 ; i <= 9; i++) {
  473.            
  474.             for (int j = 1 ; j <= i; j++) {
  475.                
  476.                 if (i % 4 == 1 || i % 4 == 2) {
  477.                     System.out.print(i);
  478.                 }
  479.                 else {
  480.                     System.out.print(j);
  481.                 }
  482.             }
  483.         }
  484.     }
  485.    
  486.     public static void soal23() {
  487.         for (int i = 1; i <= 9 ; i++) {
  488.            
  489.             for(int j = 1; j <= i; j++) {
  490.                
  491.                 if (i % 4 == 0 || i % 4 == 3) {
  492.                     System.out.print(i);
  493.                 }
  494.                 else {
  495.                     System.out.print(j);
  496.                 }
  497.             }
  498.         }
  499.     }
  500.    
  501.     public static void soal24() {
  502.         for (int i = 8 ; i > 0 ; i--) {
  503.            
  504.             for (int j = i ; j > 0 ; j--) {
  505.                
  506.                 if (i % 4 == 3 || i % 4 == 0) {
  507.                     System.out.print(i);
  508.                 }      
  509.                 else {
  510.                     System.out.print(j);
  511.                 }
  512.             }          
  513.         }
  514.     }
  515.    
  516.     public static void soal25() {
  517.         for (int i = 8 ; i > 0 ; i--) {
  518.            
  519.             for (int j = i ; j > 0 ; j--) {
  520.                
  521.                 if (i % 4 == 2 || i % 4 == 1) {
  522.                     System.out.print(i);
  523.                 }
  524.                 else{
  525.                     System.out.print(j);
  526.                 }
  527.             }
  528.         }
  529.     }
  530.    
  531.     public static void soal26() {
  532.        
  533.         int awal = 1;
  534.        
  535.         for (int i = 0; i < 12; i++) {
  536.             System.out.print(awal + " ");
  537.            
  538.             if (i % 2 == 0) {
  539.                 awal += 4;
  540.             }
  541.             else {
  542.                 awal -= 2;
  543.             }
  544.         }
  545.     }
  546.    
  547.     public static void soal27() {
  548.        
  549.         int awal = 2;  
  550.        
  551.         for (int i = 0; i < 10; i++) {
  552.             System.out.print(awal + " ");
  553.            
  554.             if (i % 2 == 0) {
  555.                 awal += 10;
  556.             }
  557.             else {
  558.                 awal -= 5;
  559.             }
  560.         }
  561.     }
  562.    
  563.     public static void soal28() {
  564.        
  565.         int awal = 5;
  566.        
  567.         for (int i = 0; i < 12; i++) {
  568.             System.out.print(awal + " ");
  569.            
  570.             if (i % 2 == 0) {
  571.                 awal -= 3;
  572.             }
  573.             else {
  574.                 awal += 5;
  575.             }
  576.            
  577.         }
  578.        
  579.     }
  580.    
  581.     public static void soal29() {
  582.        
  583.         int awal = 3, ratio = 1;
  584.        
  585.         for (int i = 0; i < 5; i++) {
  586.             System.out.print(awal + " ");
  587.             System.out.print(awal * 3 + " ");
  588.             awal += ratio;
  589.             ratio *= 3;
  590.            
  591.         }
  592.     }
  593.    
  594.     public static void soal30() {
  595.        
  596.         int awal = 1;
  597.        
  598.         for (int i = 1; i < 14; i++) {
  599.             System.out.print(awal + " ");
  600.             if (i % 3 == 0) {
  601.                 awal += 3;
  602.             }
  603.             else if (i % 3 == 1) {
  604.                 awal += 1;
  605.             }
  606.             else {
  607.                 awal += 2;
  608.             }
  609.         }
  610.     }
  611.    
  612.     public static void soal31() {
  613.        
  614.         int awal = 1;
  615.        
  616.         while (awal <= 512) {
  617.             System.out.print(awal + " ");
  618.             awal *= 2;
  619.         }
  620.     }
  621.    
  622.     public static void soal32() {
  623.        
  624.         int angka1 = 0, angka2 = 1, angka3 = 0;
  625.        
  626.         while (angka1 <= 34) {
  627.            
  628.             System.out.print(angka1 + " ");
  629.            
  630.             angka3 = angka1 + angka2;
  631.             angka1 = angka2;
  632.             angka2 = angka3;
  633.  
  634.         }
  635.     }
  636.    
  637.     public static void soal33() {
  638.        
  639.         int angka1 = 0, angka2 = 1, angka3 = 0, i = 0;
  640.        
  641.         do {
  642.             System.out.print(angka1 + " ");
  643.            
  644.             angka3 = angka1 + angka2;
  645.             angka1 = angka2;
  646.             angka2 = angka3;
  647.             i++;
  648.            
  649.         } while(i < 10);
  650.     }
  651.    
  652.     public static void soal34() {
  653.        
  654.         for (int i = 1; i <= 3; i++) {
  655.            
  656.             for (int j = 1; j <= 10; j++ ) {
  657.                 System.out.print("1" + " ");
  658.             }
  659.             System.out.println();
  660.         }
  661.     }
  662.    
  663.     public static void soal35() {
  664.        
  665.         for (int i = 1; i <= 3; i++) {
  666.            
  667.             for (int j = 1; j <= (i * 3); j++) {
  668.                
  669.                 System.out.print("1" + " ");
  670.             }
  671.             System.out.println();
  672.         }
  673.     }
  674.    
  675.     public static void soal36() {
  676.        
  677.         int awal = 2;
  678.        
  679.         for (int i = 1; i <= 16; i++) {
  680.            
  681.             System.out.print(awal + " ");
  682.            
  683.             if (i % 2 == 0) {
  684.                 awal += 7;
  685.             }
  686.             else {
  687.                 awal -= 5;
  688.             }
  689.         }
  690.     }
  691.    
  692.     public static void soal37() {
  693.        
  694.         for (int i = 1; i <= 18; i++) {
  695.            
  696.             if (i % 3 == 0) {
  697.                 System.out.print("1" + " ");
  698.             }
  699.             else if (i % 3 == 1) {
  700.                 System.out.print("0" + " ");
  701.             }
  702.             else {
  703.                 System.out.print("*" + " ");
  704.             }
  705.         }
  706.     }
  707.    
  708.     public static void soal38() {
  709.        
  710.         for (int i = 1; i <= 1000000; i *= 10) {
  711.            
  712.             System.out.print(i + " ");
  713.         }
  714.     }
  715.    
  716.     public static void soal39() {
  717.        
  718.         for (int i = 1; i <= 3; i++) {
  719.            
  720.             for (int j = 1; j <= 7; j++) {
  721.                 System.out.print("*" + " ");
  722.             }
  723.             System.out.println();
  724.         }
  725.     }
  726.    
  727.     public static void soal40() {
  728.        
  729.         for (int i = 1; i <= 3; i++) {
  730.            
  731.             for (int j = 1; j <= 5; j++) {
  732.                 System.out.print("1" + " ");
  733.             }
  734.             System.out.println();
  735.         }
  736.     }
  737.    
  738.     public static void soal41() {
  739.        
  740.         for (int i = 1; i <= 4; i++) {
  741.            
  742.             for (int j = 1; j <= 7; j++) {
  743.                
  744.                 System.out.print(i + " ");
  745.             }
  746.             System.out.println();
  747.         }
  748.     }
  749.    
  750.     public static void soal42() {
  751.        
  752.         for (int i = 1; i <= 5; i++) {
  753.            
  754.             for (int j = 1; j <= 7; j++) {
  755.                
  756.                 System.out.print(j + " ");
  757.             }
  758.             System.out.println();
  759.         }
  760.     }
  761.    
  762.     public static void soal43() {
  763.        
  764.         for (int i = 1; i <= 7; i++) {
  765.            
  766.             for (int j = 1; j <= i; j++) {
  767.                
  768.                 System.out.print(i + " ");
  769.             }
  770.             System.out.println();
  771.         }
  772.     }
  773.    
  774.     public static void soal44() {
  775.        
  776.         for (int i = 1; i <= 7; i++) {
  777.            
  778.             for (int j = 1; j <= i; j++) {
  779.                
  780.                 System.out.print(j + " ");
  781.             }
  782.             System.out.println();
  783.         }
  784.     }
  785.    
  786.     public static void soal45() {
  787.        
  788.         for (int i = 1; i <= 3; i++) {
  789.            
  790.             for (int j = 1; j <= 7; j++) {
  791.                
  792.                 System.out.print(i + "." + j + " ");
  793.             }
  794.             System.out.println();
  795.         }
  796.     }
  797.    
  798.     public static void soal46() {
  799.        
  800.         for (int i = 1; i <= 5; i++) {
  801.            
  802.             for (int j = 1; j <= i; j++) {
  803.                
  804.                 System.out.print("*" + " ");
  805.             }
  806.             System.out.println();
  807.         }
  808.     }
  809.    
  810.     public static void soal47() {
  811.        
  812.         for (int i = 5; i >= 1; i--) {
  813.            
  814.             for (int j = 1; j <= i; j++) {
  815.                
  816.                 System.out.print("*" + " ");
  817.             }
  818.             System.out.println();
  819.         }
  820.     }
  821.    
  822.     public static void soal48(){
  823.        
  824.         for (int i = 1; i <= 4; i++) {
  825.            
  826.             for (int j = 4; j > i; j--) {
  827.                 System.out.print("  ");
  828.             }
  829.            
  830.             for (int k = 1; k < i*2; k++) {
  831.                 System.out.print("*" + " ");
  832.             }
  833.             System.out.println();
  834.         }
  835.     }
  836.    
  837.     public static void soal49() {
  838.        
  839.         for (int i = 1; i <= 4; i++) {
  840.            
  841.             for (int j = 1; j <= i+2; j++) {
  842.                 System.out.print("*" + " ");
  843.             }
  844.             System.out.println();
  845.         }
  846.     }
  847. }
  848.  
Advertisement
Add Comment
Please, Sign In to add comment