0% found this document useful (0 votes)
6 views10 pages

Pemograman P3

The document contains source code for 3 Java programs that perform matrix operations: 1) A program that inputs course data (name, theory score, practical score), calculates the average, and outputs the results in a table. 2) A program that inputs a matrix, rotates the elements, and outputs the rotated matrix. 3) A program that inputs two matrices, multiplies them, and outputs the result matrix.

Uploaded by

ilhammaliki03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Pemograman P3

The document contains source code for 3 Java programs that perform matrix operations: 1) A program that inputs course data (name, theory score, practical score), calculates the average, and outputs the results in a table. 2) A program that inputs a matrix, rotates the elements, and outputs the rotated matrix. 3) A program that inputs two matrices, multiplies them, and outputs the result matrix.

Uploaded by

ilhammaliki03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

NAMA : Ilham Maliki

NPM : 202143502444

Kelas : R37

Mata Kuliah : Pemograman 3

SOAL 1

INPUT :
OUTPUT :

SOURCE CODE

import java.util.Scanner;

public class pertemuan3

{ public static void main(String[]args){

Scanner input = new Scanner(System.in);

System.out.println("----------------------------------------------------------------");

System.out.print("Jumlah Data : " ); int jumlah=input.nextInt();

System.out.println("----------------------------------------------------------------");

int data[][] = new int[jumlah][50];

String matakuliah[][] = new String[jumlah][50];

for(int i=0;i<jumlah;i++){

System.out.println();

System.out.print("Mata Kuliah : "); matakuliah[i][0] = input.next();

System.out.print("Nilai Teori : "); data[i][1] = input.nextInt();


System.out.print("Nilai Praktikum : "); data[i][2] = input.nextInt();

}
System.out.println();

System.out.println("-------------------------------------------------------------------");

System.out.println("Mata Kuliah\tTeori\tPraktikum\tRata-Rata");

System.out.println("-------------------------------------------------------------------");

for(int i=0;i<jumlah;i++)

{ int hasil=(data[i][1]+data[i]

[2]); float mean = (hasil/2);

System.out.print(matakuliah[i][0]+"\t\t"+data[i][1]+"\t"+data[i][2]+"\t\t"+mean);

System.out.println();

SOAL 2

INPUT :
OUTPUT

OUTPUT :
SOURCE CODE :

import java.util.Scanner; public class

Matriks1{ public static void main(String[]

args) { Scanner inp = new

Scanner(System.in); int baris,kolom;

System.out.print("Masukan Baris : ");

baris = inp.nextInt();

System.out.print("Masukan Kolom : ");

kolom = inp.nextInt(); int [][] matriks = new

int[baris+1][kolom+1]; int[][] rotasi = new

int[baris+1][kolom+1];

System.out.println("");

System.out.println("Masukan Elemen Matriks");

for(int i = 1; i <= baris; i++){

for(int j = 1; j <= kolom; j++){

System.out.print("Baris " + (i) + " Kolom " + (j) + " : "); matriks[i]
[j] = inp.nextInt();

System.out.println("");
System.out.println("Elemen Matriks");

for(int i = 1; i <= baris; i++){ for(int j

= 1; j <= kolom; j++){

System.out.print(matriks[i][j]+" ");

System.out.println();

System.out.println("");

System.out.println("Hasil Rotasi Elemen Matriks");

for(int i = 1; i <= kolom; i++){

for(int j = baris; j >= 1; j--){

System.out.print(matriks[j][i]+" ");

System.out.println();

SOAL 3

INPUT :
\

OUTPUT :
SOURCE CODE :

import java.util.Scanner; public class

matriks2{ public static void main(String[]

args) { Scanner input = new

Scanner(System.in);

int a,b,c,d,e,f;

System.out.print("Masukan N : ");

a = input.nextInt();

System.out.print("Masukan M : ");
b = input.nextInt();

System.out.print("Masukan P : ");

c = input.nextInt(); int matriks[][] =

new int[a+1][b+1]; int matriks2[][]

= new int[b+1][c+1]; int h[][]= new

int[a][c]; System.out.println("");

System.out.println("Masukan Elemen Matriks 1");

for (d = 0; d < a; d++){

for(e = 0; e < b; e++){

System.out.print("Baris " + (d+1) + " Kolom " + (e+1) + " : ");

matriks[d][e] = input.nextInt();

System.out.println("");

System.out.println("Masukan Elemen Matriks 2");

for(d = 0; d < b; d++){ for(e = 0; e < c; e++){

System.out.print("Baris " + (d+1) + " Kolom " + (e+1) + " : ");

matriks2[d][e] = input.nextInt();

System.out.println("");

System.out.println("Elemen Matriks");

for(d = 0; d < a; d++){

for(e = 0; e < b; e++){

System.out.print(matriks[d][e]+"\t");

System.out.println();

for(d = 0; d < b; d++)

{ for(e = 0; e < c; e++){

System.out.print(matriks2[d][e]+"\t");

System.out.println();
}

System.out.println();

System.out.println("Hasil Perkalian Matriks");

for (d=0; d<a; d++)

for (e=0;e<c; e++)

h[d][e]=0;

for (f=0; f<b; f++)

h[d][e] +=(matriks[d][f]*matriks2[f][e]);

System.out.print(h[d][e]+"\t");

System.out.println();

You might also like