|
| 1 | +```java |
| 2 | +package csd; |
| 3 | + |
| 4 | +class App { |
| 5 | + public static void main(String [] args) |
| 6 | + { |
| 7 | + |
| 8 | + //... |
| 9 | + |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +class PatternTest { |
| 14 | + public static void run() |
| 15 | + { |
| 16 | + java.util.Scanner kb = new java.util.Scanner(System.in); |
| 17 | + System.out.println("Merdiven Çizimi: ?"); |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + System.out.println("Yükseklik:"); |
| 23 | + int height = Integer.parseInt(kb.nextLine()); |
| 24 | + System.out.println("Genişlik:"); |
| 25 | + int width = Integer.parseInt(kb.nextLine()); |
| 26 | + Pattern.createPattern(height, width); |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +class Pattern{ |
| 34 | + public static void createPattern (int height,int width) |
| 35 | + { |
| 36 | + |
| 37 | + boolean starFlag = true; |
| 38 | + int starPos = 1; |
| 39 | + for(int i = 0; i < height; i++){ |
| 40 | + { |
| 41 | + System.out.print("<"); |
| 42 | + if (starPos <= width && starFlag){ |
| 43 | + displayStarLeftToRight(starPos,width); |
| 44 | + starPos++; |
| 45 | + if (starPos > width){ |
| 46 | + starPos -= 2; |
| 47 | + starFlag = false; |
| 48 | + } |
| 49 | + } |
| 50 | + else if (starPos <= width && !starFlag) { |
| 51 | + displayStarRightToLeft(starPos, width); |
| 52 | + starPos--; |
| 53 | + if (starPos < 1){ |
| 54 | + starPos += 2; |
| 55 | + starFlag = true; |
| 56 | + } |
| 57 | + |
| 58 | + } |
| 59 | + System.out.println(">"); |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + } |
| 64 | + } |
| 65 | + public static void displayStarLeftToRight(int starPos,int width) |
| 66 | + { |
| 67 | + for (int i = 1; i <= width; i++){ |
| 68 | + if ((i == starPos)) |
| 69 | + System.out.print("*"); |
| 70 | + else |
| 71 | + System.out.print("_"); |
| 72 | + } |
| 73 | + } |
| 74 | + public static void displayStarRightToLeft(int starPos,int width) |
| 75 | + { |
| 76 | + |
| 77 | + for (int i = 1; i <= width; i++){ |
| 78 | + if ((i == starPos)) |
| 79 | + System.out.print("*"); |
| 80 | + else |
| 81 | + System.out.print("_"); |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +class GetPrimeFactorTest{ |
| 87 | + public static void run() |
| 88 | + { |
| 89 | + java.util.Scanner kb = new java.util.Scanner(System.in); |
| 90 | + System.out.println("Bir tamsayı giriniz:"); |
| 91 | + int ival; |
| 92 | + while( (ival = Integer.parseInt(kb.nextLine())) > 0 ){ |
| 93 | + System.out.println("Asal Çarpanlar gösteriliyor:"); |
| 94 | + GetPrimeFactor.displayPrimeFactor(ival); |
| 95 | + System.out.println("Yeni bir tamsayı giriniz:"); |
| 96 | + System.out.println("Çıkmak için 0'a basınız:"); |
| 97 | + |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | +class GetPrimeFactor { |
| 102 | + |
| 103 | + |
| 104 | + public static void displayPrimeFactor(int ival) |
| 105 | + { |
| 106 | + int i = 2; |
| 107 | + if (ival < i){ |
| 108 | + System.out.printf("%d sayısının asal çarpanları yok",ival); |
| 109 | + return; |
| 110 | + } |
| 111 | + while (i <= ival){ |
| 112 | + if ((NumberUtil.isPrime(i) && ival % i == 0)){ |
| 113 | + System.out.printf("%d ",i); |
| 114 | + ival /= i; |
| 115 | + continue; |
| 116 | + } |
| 117 | + i++; |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | +class DisplayDurationAppTest{ |
| 127 | + public static void run() |
| 128 | + { |
| 129 | + java.util.Scanner kb = new java.util.Scanner(System.in); |
| 130 | + System.out.println("Tamsayı türden bir saniye değeri giriniz:"); |
| 131 | + long second = Long.parseLong(kb.nextLine()); |
| 132 | + for(;;){ |
| 133 | + int n = 1000000000; |
| 134 | + while (n-- > 0) |
| 135 | + ; |
| 136 | + DisplayDurationApp.displayDuration(second--); |
| 137 | + System.out.printf("%n"); |
| 138 | + if(second == 0) |
| 139 | + break; |
| 140 | + } |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +class DisplayDurationApp { |
| 145 | + public static void displayDuration(long second) |
| 146 | + { |
| 147 | + |
| 148 | + if (second / 3600 > 0) |
| 149 | + System.out.printf("%d hour ",second / 3600); |
| 150 | + if ((second % 3600) / 60 > 0) |
| 151 | + System.out.printf("%d minute ", (second % 3600) / 60); |
| 152 | + if (second % 60 > 0) |
| 153 | + System.out.printf("%d second ", second %= 60); |
| 154 | + } |
| 155 | + |
| 156 | +} |
| 157 | + |
| 158 | +class DiamondShapeAppTest{ |
| 159 | + public static void run() |
| 160 | + { |
| 161 | + java.util.Scanner kb = new java.util.Scanner(System.in); |
| 162 | + System.out.printf("Baklava çizimi için bir tamsayı giriniz:"); |
| 163 | + int ival = Integer.parseInt(kb.nextLine()); |
| 164 | + System.out.println("İşte Nefis Baklava:"); |
| 165 | + DiamondShapeApp.CreateDiamondShape(ival); |
| 166 | + } |
| 167 | +} |
| 168 | + |
| 169 | +class DiamondShapeApp { |
| 170 | + public static void CreateDiamondShape(int n) |
| 171 | + { |
| 172 | + int maxStarNumber = 2*n - 1; |
| 173 | + for (int i = 0, j = 1; i < n; i++, j += 2){ |
| 174 | + displayStar(j, maxStarNumber); |
| 175 | + if (j == maxStarNumber){ |
| 176 | + j -=2; |
| 177 | + for (int k = 1; k < n; k++,j -= 2){ |
| 178 | + displayStar(j, maxStarNumber); |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + public static void displayStar(int currentStarNumber,int maxStarNumber) |
| 185 | + { |
| 186 | + int spaceNumber = maxStarNumber - currentStarNumber; |
| 187 | + for (int i = 0;i < maxStarNumber; i++){ |
| 188 | + if (i == spaceNumber / 2){ |
| 189 | + while(currentStarNumber-- > 0){ |
| 190 | + System.out.printf("*"); |
| 191 | + i++; |
| 192 | + } |
| 193 | + } |
| 194 | + System.out.printf(" "); |
| 195 | + } |
| 196 | + System.out.printf("%n"); |
| 197 | + } |
| 198 | + |
| 199 | +} |
| 200 | + |
| 201 | +``` |
0 commit comments