Muhamad Yadi B.1910712 Uts Algoritma

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

UTS ALGORITMA DAN PEMROGRAMAN KOMPUTER

NAMA : MUHAMAD YADI

NIM : B.1910712

PRODI : TIP (sore)

1. import java.util.Scanner;

public class UTS {

public static void main(String[] args) {

int a,b;

for (a=1; a<=4; a++){

for(b=1; b<=a; b++)

System.out.print("*");

System.out.println();

run:

**

***

****

BUILD SUCCESSFUL (total time: 0 seconds)


2. import java.util.Scanner;

public class Luassegitiga {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

double A1,A2,A3,A4,A5, T1,T2,T3,T4,T5, L1,L2,L3,L4,L5;

System.out.print("Alas ke-1 = ");

A1 = input.nextDouble();

System.out.print("Alas ke-2 = ");

A2 = input.nextDouble();

System.out.print("Alas ke-3 = ");

A3 = input.nextDouble();

System.out.print("Alas ke-4 = ");

A4 = input.nextDouble();

System.out.print("Alas ke-5 = ");

A5 = input.nextDouble();

System.out.print("Tinggi ke-1 = ");

T1 = input.nextDouble();

System.out.print("Tinggi ke-2 = ");

T2 = input.nextDouble();

System.out.print("Tinggi ke-3 = ");

T3 = input.nextDouble();

System.out.print("Tinggi ke-4 = ");

T4 = input.nextDouble();

System.out.print("Tinggi ke-5 = ");

T5 = input.nextDouble();

L1 = 0.5 * A1 * T1;

System.out.println("Luas Segi Tiga 1 = " + L1);

L2 = 0.5 * A2 * T2;

System.out.println("Luas Segi Tiga 2 = " + L2);

L3 = 0.5 * A3 * T3;
System.out.println("Luas Segi Tiga 3 = " + L3);

L4 = 0.5 * A4 * T4;

System.out.println("Luas Segi Tiga 4 = " + L4);

L5 = 0.5 * A5 * T5;

System.out.println("Luas Segi Tiga 5 = " + L5);

run:

Alas ke-1 = 2

Alas ke-2 = 4

Alas ke-3 = 6

Alas ke-4 = 8

Alas ke-5 = 10

Tinggi ke-1 = 12

Tinggi ke-2 = 14

Tinggi ke-3 = 16

Tinggi ke-4 = 18

Tinggi ke-5 = 20

Luas Segi Tiga 1 = 12.0

Luas Segi Tiga 2 = 28.0

Luas Segi Tiga 3 = 48.0

Luas Segi Tiga 4 = 72.0

Luas Segi Tiga 5 = 100.0

BUILD SUCCESSFUL (total time: 18 seconds)

3. import java.util.Scanner;

public class Kuadrat {

public static void main(String[] args) {


Scanner n = new Scanner(System.in);

int input;

System.out.print("masukkan jumlah data yang akan di input : ");

input = n.nextInt();

int[] array = new int[input];

for(int x=0; x<array.length; x++){

System.out.print("masukkan array 0 : " );

array [x] = n.nextInt();

//

for(int y : array){

int nilai = y;

int pangkat = 2;

double hasil;

hasil = Math.pow(nilai,pangkat);

System.out.println("hasil array :" + hasil");

run:

masukkan jumlah data yang akan di input : 5

masukkan array 0 : 2
masukkan array 0 : 3

masukkan array 0 : 4

masukkan array 0 : 5

masukkan array 0 : 6

hasil array :4.0

hasil array :9.0

hasil array :16.0

hasil array :25.0

hasil array :36.0

BUILD SUCCESSFUL (total time: 8 seconds)

You might also like