array multidimensi
*** ARRAY MULTI DIMENSI
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author anik nurul
*/
public class tugas1 {
public static void
main( String[] args ){
int data2[][]={{4,6,4,2,8,4,2,10},{4,6,4,2,8,4,2,10}};
for(int a=0;a<data2.length;a++){
for(int b=0;b<data2[0].length;b++){
System.out.print(data2[a][b]+" ");
}
System.out.print("\n");
}
}
}
*** MEMBUAT NAMA DENGAN ARAY MULTI DIMENSI
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author pemrograman
*/
public class tugas2 {
public static void
main(String[] args) {
String
data[][] = {{"ABDUL\t085646668991\tKediri"},
{"KUSNO\t08564666899\tTrenggalek"},
{"PONIRAN\t085646668999\tBojonegoro"}};
int i = 0;
System.out.println("Nama: \tNo: \t\tAlamat");
while (i <
data.length) {
int j = 0;
while (j
< data[0].length) {
System.out.println(data[i][j] + " ");
j++;
}
System.out.println();
i++;
}
}
}
*** MENCARI RATA RATA DENGAN ARRAY MULTI DIMENSI
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author anik nurul
*/
public class tugas2A {
public static void
main( String[] args ){
int data2[][]={{4,6,4,2,8,4,2,10},{4,6,4,2,8,4,2,10}};
int jumlah = 0;
int rata;
for(int a=0;a<data2.length;a++){
for(int b=0;b<data2[0].length;b++){
System.out.print(data2[a][b]+" ");
jumlah +=data2[a][b];
}
System.out.print("\n");
}
rata=jumlah/data2.length;
System.out.println("rata-rata "+rata);
}
}
*** MENGGANTI NILAI ARAY DENGAN INPUT
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author anik nurul
*/
import javax.swing.*;
public class tugas2B {
public static void
main(String[] args) {
int data[][] =
{{4, 6, 4, 7, 8, 3, 2, 10}, {4, 6, 4, 2, 8, 8, 2, 10}};
int nilai =
Integer.parseInt(JOptionPane.showInputDialog("Masukkan angka yang anda
cari indeknya"));
for (int a =
0; a < data.length; a++) {
for (int b
= 0; b < data[0].length; b++) {
if (nilai == data[a][b]) {
System.out.println(nilai +" adalah indek ke
"+a+" dan indek ke "+b);
int nilai2 =
Integer.parseInt(JOptionPane.showInputDialog("angka yang anda ingin
masukkan"));
data[a][b] = nilai2;
}
System.out.println("data "+data[a][b]);
}
}
}
}
*** ARAY NAMA
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author pemrograman
*/
public class tugas3 {
public static void
main(String[] args) {
String
data[][] = {{"ABDUL\t085646668991\tKediri"},
{"KUSNO\t08564666899\tTrenggalek"},
{"PONIRAN\t085646668999\tBojonegoro"}};
int i = 0;
System.out.println("Nama: \tNo: \t\tAlamat");
while (i <
data.length) {
int j = 0;
while (j
< data[0].length) {
System.out.println(data[i][j] + " ");
j++;
}
System.out.println();
i++;
}
}
}
*** MENCARI ARRAY MATRIK
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author anik nurul
*/
import javax.swing.*;
public class tugas4AMatrik {
public static void
main(String[] args) {
int matrik
[][]={{2,9},{1,5}};
int
matrik1[][]={{5,17},{10,4}};
int baris=0;
int kolom=0;
int baris1=0;
int kolom1=0;
int
[][]jumlah=new int[matrik.length][matrik1.length];
String
angka=JOptionPane.showInputDialog("Masukkan angka");
int
cari=Integer.parseInt(angka);
for(int
a=0;a<matrik.length;a++){
for(int
b=0;b<matrik[0].length;b++)
if
(matrik[a][b]==cari){
baris=a+1;
kolom=b+1;
}
}System.out.println("indek array:"+" pada
baris:"+baris+" pada kolom:"+kolom);
for(int
a=0;a<matrik1.length;a++){
for(int
b=0;b<matrik1[0].length;b++)
if
(matrik1[a][b]==cari){
baris1=a+1;
kolom1=b+1;
}
} System.out.println("indek
array2:"+" pada baris:"+baris1+" pada kolom:"+kolom1);
}
}
*** PENJULAHAN MATRIK
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
public class tugas4BMatrik {
public static void
main(String[] args) {
int matrik
[][]={{2,9},{1,5}};
int
matrik1[][]={{5,17},{10,4}};
int jumlah
[][]=new int[matrik.length][matrik[0].length];
System.out.println("Data matrik 1:");
for(int
i=0;i<matrik.length;i++){
for(int
j=0;j<matrik[0].length;j++){
System.out.print(matrik[i][j]+" ");
} System.out.println();
}
System.out.println("Data
matrik 2:");
for(int
i=0;i<matrik1.length;i++){
for(int
j=0;j<matrik1[0].length;j++){
System.out.print(matrik1[i][j]+" ");
} System.out.println();
}
for(int
i=0;i<jumlah.length;i++){
for(int
j=0;j<jumlah[0].length;j++){
jumlah[i][j]=matrik[i][j]+matrik1[i][j];
} System.out.println();
}
System.out.println("Hasil penjumlahan");
for(int
i=0;i<matrik1.length;i++){
for(int
j=0;j<matrik1[0].length;j++){
System.out.print(jumlah[i][j]+" ");
} System.out.println();
}
}
}
**** MEMBUAT NILAI DENGAN ARAY
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package modul6;
/**
*
* @author Ayu
*/
public class tugas5 {
public static
void main(String[] args) {
String[]mahasiswa={"Joni","Toni","Bekti","Rudi"};
String[]matakuliah={"Daspro","RPL","Jarkom","PCD"};
int[][]ni={{70,80,50,90},{90,40,60,40},{50,90,40,40},{60,80,80,40}};
int jumlah[][]=new
int[4][4];
double rata_rata[] =
new double[4];
for(int a=0;a<jumlah.length;a++) {
for (int
b=0;b<jumlah[0].length;b++) {
jumlah[0][0] =
jumlah[0][0] + ni[a][0];
jumlah[1][1] =
jumlah[1][1] + ni[a][1];
jumlah[2][2] =
jumlah[2][2] + ni[a][2];
jumlah[3][3] =
jumlah[3][3] + ni[a][3];
}
}
for(int
b=0;b<rata_rata.length;b++) {
rata_rata[b] =
jumlah[b][b]/rata_rata.length;
}
System.out.print("DATA PEhasilnyaAN MAHASISWA TEKNIK INFORMATIKA
\n"
+
"========================================================\n"
+
"Nama | Mata Kuliah |\n"
+
" | daspro | RPL | JARKOM | PCD
| RATA2 | HURUF | \n"
+
"---------------------------------------------------------\n");
String
[]hasilnya = new String[4];
String
max1=null,min1=null;
int
bantuan2,bantuan3,bantuan4,bantuan1;
String
bantuan5,bantuan6;
double bantuan;
for(int
i=0;i<rata_rata.length;i++) {
if((rata_rata[i] <=100) && (rata_rata[i]>=86)) {
hasilnya[i] = "A";
}else
if((rata_rata[i] <=85) && (rata_rata[i]>=76)) {
hasilnya[i] = "B+";
}else
if((rata_rata[i] <=75) && (rata_rata[i]>=66)) {
hasilnya[i] = "B";
}else
if((rata_rata[i] <=65) && (rata_rata[i]>=56)) {
hasilnya[i] = "C+";
}else
if((rata_rata[i] <=55) && (rata_rata[i]>=46)) {
hasilnya[i] = "C";
}else {
System.out.println("salah");
}
}
double min =
rata_rata[0];
double max =
0.0;
for (int
a=0;a<hasilnya.length;a++) {
for (int
k=0;k<hasilnya.length;k++) {
System.out.print(ni[a][k]+" | "+ni[a][k]+" | "+ni[a][k]+"
| "+ni[a][k]+" | "+ni[a][k]);
}
System.out.println(" | "+rata_rata[a]+" |
"+hasilnya[a]+" | ");
}
for (int
l=0;l<hasilnya.length;l++) {
if
(min>rata_rata[l]) {
min =
rata_rata[l];
min1 = mahasiswa[l];
}
if
(max<rata_rata[l]) {
max =
rata_rata[l];
max1 =
mahasiswa[l];
}
}
System.out.println("hasilnya rata rata tertinggi adalah
"+max1+" dengan hasilnya "+max);
System.out.println("hasilnya rata rata terrendah adalah
"+min1+" dengan hasilnya "+min);
}
}
Comments
Post a Comment