0% found this document useful (0 votes)
61 views13 pages

Laporan Praktikum Algoritma Dan Pemrograman: Pertemuan Ke - 5

The document discusses Java programming concepts and practical exercises using NetBeans IDE 8.2. It covers declaring and initializing boolean variables, equality and assignment operators, relational operators, and if statements. The practical exercises demonstrate creating boolean variables, comparing values, and conditional logic using if statements to check conditions and print outputs. The code examples declare variables, use comparison and logical operators, and demonstrate basic Java programming constructs like if statements.

Uploaded by

Novita Ceniz
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)
61 views13 pages

Laporan Praktikum Algoritma Dan Pemrograman: Pertemuan Ke - 5

The document discusses Java programming concepts and practical exercises using NetBeans IDE 8.2. It covers declaring and initializing boolean variables, equality and assignment operators, relational operators, and if statements. The practical exercises demonstrate creating boolean variables, comparing values, and conditional logic using if statements to check conditions and print outputs. The code examples declare variables, use comparison and logical operators, and demonstrate basic Java programming constructs like if statements.

Uploaded by

Novita Ceniz
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/ 13

20

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

grade = passed; // var grade same with var passed

System.out.println(passed); //display passed on the screen


System.out.println(largeVanue); //display largepassed on the screen
System.out.println(grade); //display grade on the screen
}

OUTPUT :

b. Boolean data type Scenario


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 LatihanVariableBoolean2 { //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 LatihanVariableBoolean2 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

String straight = "gym";//Create variable Type String

String right = "restaurant";//Create variable Type String

boolean isLeft = false; //var isLeft not will be displayed because the value
false

boolean isStraight = true; //var isStraight will be displayed because the


value true

boolean isRight = false; //var isRight not will be displayed because the
value false

System.out.println("GO straight ahead");//display text on the


screen
}

OUTPUT :

PRACTICAL 2: Expression and variable

a. Equality and assignment

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

System.out.println(x==5);//display Equality on the screen

boolean isFive = x==5;// Create variable Type boolean and Equality


System.out.println(isFive);//display Equality on the screen
}

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

System.out.println("res1: " +res1); //display Variable

int value1 = 15;// Create variable Type Integer and input value

int value2 = 24;// Create variable Type Integer and input value

boolean res2 = value1==value2; ;// Create variable Type boolean


and Equality
System.out.println("res2: "+res2); //display Variable

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

int b = 20; //Create variable Type Integer and input value

System.out.println(a==b); //display Equality on the screen

System.out.println(a!=b); //display not Equality on the screen

System.out.println(a>b); //display operator on the screen

System.out.println(a<b); //display operator on the screen

System.out.println(b>=a); //display operator on the screen

System.out.println(b<=a); //display operator on the screen

OUTPUT :

PRACTICAL 3 : CONDITIONAL STATEMENTS

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

System.out.println("Turn Left"); //display results 1

if ("gym".equals(straight)){ //Statement 2

System.out.println("Drive Straight"); //display results 2

if ("gym".equals(right)){ //Statement 3

System.out.println("Turn Right"); //display results 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

if (grade > 88){ //Statement 1

System.out.println("You made the Honor Roll"); //display


result 1
}
if (grade<=88){ //Statement 2

System.out.println("You are eligible for


tutorial");//display result 2

OUTPUT :

PRAKTIK 4 : Choosing between Two Alternatitive


a. Statemen If/Else

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

double temperature = getTemperature(); //create var type double

if(temperature <= 32.0){ //statement 1

forecast = "SNOW"; //result 1

else { //statement 2

forecast = "RAIN"; //result 2

System.out.println(forecast); //display variable

private static double getTemperature() { //declaration method

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

if (grade > 88){ //statement 1

System.out.println("You made the Honor Roll"); //result 1

else{ //statement 2

System.out.println("Your passed"); //result 2

OUTPUT :

PRACTICAL 5 : Comparing String Variables


a. Comparison of primitive variables
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 LatihanComparing1 { //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 LatihanComparing1 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 = 3; //Create variable Type integer and input value

int y = 2; //Create variable Type integer and input value

int z = x+y; //Create variable Type integer and input value

boolean test = (z==x+y); //Create variable Type boolean and input value
equality

System.out.println(test); //display variable

OUTPUT :

b. Comparison of String variables

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

String y ="cle"; //Create variable Type String and input value

String z = x+y; //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 :

c. Perbandingan String value

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

String y ="cle"; //Create variable Type String and input value

String z = x+y; //Create variable Type String and input value

boolean test = z.equals(x+y); //Create variable Type boolean and fuction


equality

System.out.println(test); //display variable

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

int nAge; //create new variable type integer

boolean drivingUnderAge; //create new variable type boolean

System.out.println("Enter your Age : "); //input value on screen

nAge = input.nextInt(); //input into variable

if (nAge<=18){ //statement 1

drivingUnderAge = false; //result boolean 1

else { //statement 2

drivingUnderAge = true; //result boolean 2

System.out.println(drivingUnderAge); //display variable

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

int bil; //create new variable type integer

System.out.println("Enter a number : "); //input value on screen

bil = input.nextInt(); //input into variable

if (bil%2==0) { //statement 1

System.out.println("The Number is even" +bil); //result 1,


display variable
}

else { //statement 2

System.out.println("The Number is odd" +bil); //result 2,


display variable
}

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

String name; //create new variable type String

System.out.println("Enter your name : "); //input on the screen

name = input.nextLine(); //input into variable

if (name.equals ("Moe")){ //statement 1 with equals function

System.out.println("You are the king rock and roll");


//result 1, display text on screen
}

else { //statement 2

System.out.println("You are the not king"); //result 2, display


text on screen
}

OUTPUT :

You might also like