Laporan Praktikum Algoritma Dan Pemrograman: Pertemuan Ke - 5
Laporan Praktikum Algoritma Dan Pemrograman: Pertemuan Ke - 5
LAPORAN PRAKTIKUM
ALGORITMA DAN PEMROGRAMAN
Pertemuan Ke - 5
Disusun Oleh :
NAMA : Novita
NIM : 183110020
JURUSAN : Manajemen Informatika
JENJANG : D3
STMIK AKAKOM
YOGYAKARTA
2018
LEARNING 5
JAVA WITH NETBEANS IDE 8.2
PRACTICAL 1 : Declare, initialize and use boolean variable
a. Variabel boolean
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanVariableBoolean1 { //In class declarations, consider where and how the
class is used (specify the modifier). Then give the name (identifier) that matches the information they contain
and write down the complete property declaration along with the method in sequence. Choose the appropriate
modifier to determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanVariableBoolean1 class that acts as the main method. The main method is the starting point of a Java
program. All programs except applets written in Java begin with the main method. Make sure to follow the
correct sign writing rules.
boolean passed, largeVanue, grade; //Create variable Type boolean
passed = true; //var passed will be displayed because the value true
largeVanue = false; // var largeVanue not will be displayed because the value
false
OUTPUT :
boolean isLeft = false; //var isLeft not will be displayed because the value
false
boolean isRight = false; //var isRight not will be displayed because the
value false
OUTPUT :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanEkspresi1 { //In class declarations, consider where and how the class is used
(specify the modifier). Then give the name (identifier) that matches the information they contain and write down
the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the Latihan LatihanEkspresi1 class that acts as the main method. The main method is the starting point of a
Java program. All programs except applets written in Java begin with the main method. Make sure to follow the
correct sign writing rules.
int x= 4;// Create variable Type Integer and input value
OUTPUT :
b. Boolean ekspresi
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class { //In class declarations, consider where and how the class is used (specify the modifier).
Then give the name (identifier) that matches the information they contain and write down the complete property
declaration along with the method in sequence. Choose the appropriate modifier to determine relationships with
other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanEkspresi2 class that acts as the main method. The main method is the starting point of a Java
program. All programs except applets written in Java begin with the main method. Make sure to follow the
correct sign writing rules.
boolean res1 = 24==15; ;// Create variable Type boolean and Equality value
int value1 = 15;// Create variable Type Integer and input value
int value2 = 24;// Create variable Type Integer and input value
OUTPUT :
c. Operator Relasi
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class OperatorRelasi { //In class declarations, consider where and how the class is used
(specify the modifier). Then give the name (identifier) that matches the information they contain and write down
the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the OperatorRelasi class that acts as the main method. The main method is the starting point of a Java program.
All programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
int a = 10; //Create variable Type Integer and input value
OUTPUT :
a. If statement
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanIf1 { //In class declarations, consider where and how the class is used (specify
the modifier). Then give the name (identifier) that matches the information they contain and write down the
complete property declaration along with the method in sequence. Choose the appropriate modifier to determine
relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanIf1 class that acts as the main method. The main method is the starting point of a Java program. All
programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
String left = "museum"; //Create variable Type String and input value
String straight = "gym"; //Create variable Type String and input value
String right = "restaurant"; //Create variable Type String and input value
if ("gym".equals(left)){ //Statement 1
if ("gym".equals(straight)){ //Statement 2
if ("gym".equals(right)){ //Statement 3
OUTPUT :
b. If statement
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanIf2 { //In class declarations, consider where and how the class is used (specify
the modifier). Then give the name (identifier) that matches the information they contain and write down the
complete property declaration along with the method in sequence. Choose the appropriate modifier to determine
relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanIf2 class that acts as the main method. The main method is the starting point of a Java program. All
programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
int grade = 85; //Create variable Type integer and input value
OUTPUT :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanIfElse { //In class declarations, consider where and how the class is used
(specify the modifier). Then give the name (identifier) that matches the information they contain and write down
the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanIfElse class that acts as the main method. The main method is the starting point of a Java program.
All programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
String forecast; //create variable type String
else { //statement 2
return 30.3;
}
OUTPUT :
b. If/else statement :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanIfElse2 { //In class declarations, consider where and how the class is used
(specify the modifier). Then give the name (identifier) that matches the information they contain and write down
the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanIfElse2 class that acts as the main method. The main method is the starting point of a Java program.
All programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
int grade = 85; //Create variable Type integer and input value
else{ //statement 2
OUTPUT :
boolean test = (z==x+y); //Create variable Type boolean and input value
equality
OUTPUT :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanComparing2 { //In class declarations, consider where and how the class is
used (specify the modifier). Then give the name (identifier) that matches the information they contain and write
down the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanComparing2 class that acts as the main method. The main method is the starting point of a Java
program. All programs except applets written in Java begin with the main method. Make sure to follow the
correct sign writing rules.
String x ="ora"; //Create variable Type String and input value
boolean test = (z==x+y); //Create variable Type boolean and input value
equality
System.out.println(test); //display variable
OUTPUT :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
public class LatihanComparing3 { //In class declarations, consider where and how the class is
used (specify the modifier). Then give the name (identifier) that matches the information they contain and write
down the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the LatihanComparing3 class that acts as the main method. The main method is the starting point of a Java
program. All programs except applets written in Java begin with the main method. Make sure to follow the
correct sign writing rules.
String x ="ora"; //Create variable Type String and input value
OUTPUT :
EXERCISE 1 :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
import java.util.Scanner; //create java scanner
public class Latihanmobil { //In class declarations, consider where and how the class is used
(specify the modifier). Then give the name (identifier) that matches the information they contain and write down
the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the Latihanmobil1 class that acts as the main method. The main method is the starting point of a Java program.
All programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
Scanner input = new Scanner(System.in); //input new scanner
if (nAge<=18){ //statement 1
else { //statement 2
OUTPUT :
EXERCISE 2 :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
import java.util.Scanner; // create java scanner
public class latihanganjilgenap { //In class declarations, consider where and how the class is
used (specify the modifier). Then give the name (identifier) that matches the information they contain and write
down the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the latihaganjilgenap class that acts as the main method. The main method is the starting point of a Java
program. All programs except applets written in Java begin with the main method. Make sure to follow the
correct sign writing rules.
Scanner input = new Scanner(System.in); //input new scanner
if (bil%2==0) { //statement 1
else { //statement 2
OUTPUT :
EXERCISE 3 :
package pertemuan5; //Package or package is a way of grouping and organizing classes in a library.
Package works by making new directories and folders according to the package name, then saving the file class
in that folder
import java.util.Scanner; //create java scanner
public class latihanscenario { //In class declarations, consider where and how the class is used
(specify the modifier). Then give the name (identifier) that matches the information they contain and write down
the complete property declaration along with the method in sequence. Choose the appropriate modifier to
determine relationships with other classes.
public static void main(String[] args) { //This line indicates the name of a method in
the Latihanscenario class that acts as the main method. The main method is the starting point of a Java program.
All programs except applets written in Java begin with the main method. Make sure to follow the correct sign
writing rules.
Scanner input = new Scanner(System.in); //input new java scanner
else { //statement 2
OUTPUT :