Вы находитесь на странице: 1из 16

Nama: Ashry Ramadhan

NIM: 1507112651

Tugas Pemrograman Berorientasi Objek

1.1
Tugas 1
1.1.1 Program Tugas 1

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no1;
/**
*
* @author user
*/
public class No1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int nilai = 95;
System.out.println("Nilai " + nilai);
if(nilai > 75) {
System.out.println("Lulus");
} else {
System.out.println("Tidak Lulus");
}
}
}

1.1.2

Screenshoot

Gambar 1.1 Tugas 1.

2.1

Tugas 2

2.1.1 Program Tugas 2


/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no2;
import java.util.Scanner;
/**
*
* @author user
*/
public class No2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
int nilai;
System.out.printf("Masukan nilai: ");
nilai = input.nextInt();

lima");

if(nilai%5 == 0) {
System.out.println("Nilai kelipatan
} else {
System.out.println("Nilai bukan kelipatan

lima");

}
}

2.1.2

Screenshoot

Gambar 2.1 Tugas 2.

3.1 Tugas 3
3.1.1 Program Tugas 3
/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no3;
import java.util.Scanner;
/**
*
* @author user
*/
public class No3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

// TODO code application logic here


Scanner input = new Scanner(System.in);
int nilai;
System.out.println("Masukan nilai: ");
nilai = input.nextByte();

if(nilai > 6 && nilai < 9) {


System.out.println("Memenuhi");
} else {
System.out.println("Tidak Memenuhi");
}

3.1.2

Screenshoot

Gambar 3.1 Tugas 3.

4.1 Tugas 4
4.1.1 Program Tugas 4

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no4;
import java.util.Scanner;
/**
*
* @author user
*/

public class No4 {


/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
int nilai;
System.out.println("Masukan nilai: ");
nilai = input.nextByte();
switch(nilai) {
case 7:
case 8:
System.out.println("Memenuhi");
break;
default: System.out.println("Tidak
Memenuhi");
}
input.close();
}
}

4.1.2

Screenshoot

Gambar 4.1 Tugas 4.

5.1 Tugas 5
5.1.1 Program Tugas 5

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no5;
/**
*
* @author user
*/
public class No5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i = 0;
do {
System.out.println( i + "Java");
i++;
} while(i < 10);
i=0;
System.out.println();
while(i<10) {
System.out.println( i + "Java");
i++;
}
}
}

5.1.2

Screenshoot

Gambar 5.1.1 Tugas 5.

Gambar 5.1.2 Tugas 5.

6.1 Tugas 6
6.1.1 Program Tugas 6

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no6;
/**
*
* @author user
*/
public class No6 {
/**

* @param args the command line arguments


*/
public static void main(String[] args) {
// TODO code application logic here
int i = 10;
do {
System.out.println( i + "Java");
i--;
} while(i > 0);
i=10;
System.out.println();
while(i > 0) {
System.out.println( i + "Java");
i--;
}
}
}

6.1.2

Screenshoot

Gambar 6.1.1 Tugas 6.

Gambar 6.1.2 Tugas 6.

7.1 Tugas 7
7.1.1 Program Tugas 7

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no7;
/**
*
* @author user
*/
public class No7 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int bilangan1 = 7;
int bilangan2 = 8;
int prima1 = 1;
int prima2 = 1;
int i = 2;
do {
if(bilangan1%i == 0) {
prima1 = 0;
}
} while(i != 2);
if(prima1 == 1) {
System.out.println(bilangan1 + "
Merupakan bilangan prima");
} else {
System.out.println(bilangan1 + " Bukan
bilangan prima");
}
while(i <= 3) {
if(bilangan2%i == 0) {
prima2 = 0;
}
i++;
}
if(prima2 == 1) {

System.out.println(bilangan2 + "
Merupakan111 bilangan prima");
} else {
System.out.println(bilangan2 + " Bukan
bilangan prima");
}
}
}

7.1.2

Screenshoot

Gambar 7.1. Tugas 7.

8.1 Tugas 8
8.1.1 Program Tugas 8
/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no8;
/**
*
* @author user
*/
public class No8 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i = 0;
int j = 4;

do {

System.out.println("nilai i = " + i);


System.out.println("nilai j = " + j);
i++;
j--;
} while(i < 5);
i = 0;
j = 4;
System.out.println();
while(i < 5) {
System.out.println("nilai i = " + i);
System.out.println("nilai j = " + j);
i++;
j--;
}
}
}

8.1.2

Screenshoot

Gambar 8.1.1 Tugas 8.

Gambar 8.1.2 Tugas 8.

9.1 Tugas 9
9.1.1 Program Tugas 9

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no9;
/**
*
* @author user
*/
public class No9 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
for(int i=1; i<=5; i++) {
System.out.printf("%d ",i);
}
System.out.println();
}
}

9.1.2

Screenshoot

Gambar 9.1 Tugas 9.

10.1
Tugas 10
10.1.1 Program Tugas 10

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no10;
/**
*
* @author user
*/
public class No10 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i;
int j = 1;

for(i=1; i<=5; i++) {


System.out.printf("%d",j);
}
System.out.println();

10.1.2 Screenshoot

Gambar 10.1. Tugas 10.

11.1 Tugas 11
11.1.1 Program Tugas 11

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no11;
/**
*
* @author user
*/
public class No11 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
for(int i=1; i<=5; i++) {
for(int j=1; j<=i; j++) {
System.out.printf("%d",i);
}
System.out.println();
}
System.out.println();
}
}

11.1.2 Screenshoot

Gambar 11.1. Tugas 11.

12.1
Tugas 12
12.1.1 Program Tugas 12

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates
* and open the template in the editor.
*/
package no12;
/**
*
* @author user
*/
public class No12 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
for(int i=5; i > 0; i--) {
for(int j=1; j<=i; j++) {
System.out.printf("%d",i);
}
System.out.println();
}
System.out.println();
}
}

12.1.2 Screenshoot

Gambar 12.1. Tugas 12.

Вам также может понравиться