public class PerbaikanArray {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//
String []terjemahan = {"a","b","c","d","e","f","g","h","i","j"
,"k","l","m","n","o","p","q","r","s","t"
,"u","v","w","x","y","z","
"};
String []sandi =
{"G","K","M","W","Q","Y","X","Z","N","O","P",
"A","R","U","T","V","Z","H","J","L","B","C",
"D","E","F","I","7","5","3","2","6","8","9",
"4","8","1","*"};
String kode =
JOptionPane.showInputDialog(null, "Masukkan sandi
anda").toUpperCase();
char a[] = kode.toCharArray(); // mengkonversi string ke char
for (int i = 0; i < a.length; i++) { // inputan
for (int j = 0; j < sandi.length; j++) { //output.an
if(String.valueOf(a[i]).equalsIgnoreCase(sandi[j]))
System.out.print(""+terjemahan[j]);
}
}
}
}
Perhitungan :
i = 0 dieksekusi
1 kali
i<n.lenght dieksekusi n kali
i++ dieksekusi
n kali
j = 0 dieksekusi
1 kali
j<sandi.lenght dieksekusi n x n kali
j++ dieksekusi
n x n kali
terjemahan [] dieksekusi 1 kali
sandi [] dieksekusi
1 kali
if dieksekusi
1 kali
4
+ 2n + 2n2 = T(n) = O(n2)
Posted by 20.50 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar