Postingan lainnya
Convert kodingan phyton ke java
tolong bantuannya agan" kalo ada yg bisa bantu convertin kodingan Phyton ini ke Java dong plsss
def fx(n, known_number): if n == 1: return 1 elif n == 2: return 2 else: if n < (known_number[n - 2] + 2): return 2 else: return known_number[n - 2] + 2
known_array = [] for i in range(1, 100): result = fx(i, known_array) known_array.append(result) print("Jumlah siswa: ", i, " No. urut ketua kelas: ", result)
1 Jawaban:
untuk fungsi nya <pre> public static int fx(int n, int[] knownNumber) { if(n==1) { return 1; } else if(n==2) { return 2; } else { if(n < knownNumber[n-2]+2) { return 2; } else { return knownNumber[n-2]+2; } } } </pre> untuk main class nya <pre> int[] knownArray = new int[100]; for(int i = 1; i < 100; i++) { int result = Helper.fx(i, knownArray); knownArray[i] = result; System.out.println("Jumlah siswa: " + i + " No. urut ketua kelas: " +result); } </pre>