0% found this document useful (0 votes)
29 views

Modul Praktikum PDF

The document contains Java code examples demonstrating the use of conditional and logical operators in if, if-else, switch, ternary, and nested if statements. Multiple classes are defined to check conditions on variables and print corresponding output messages. One example calculates the total price of items based on quantity thresholds. Another checks test scores and determines if a student passes a course.

Uploaded by

Alif Bakthiar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Modul Praktikum PDF

The document contains Java code examples demonstrating the use of conditional and logical operators in if, if-else, switch, ternary, and nested if statements. Multiple classes are defined to check conditions on variables and print corresponding output messages. One example calculates the total price of items based on quantity thresholds. Another checks test scores and determines if a student passes a course.

Uploaded by

Alif Bakthiar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

package alif;

class DemoIf {
public static void main(String[] args) {
int A = 10;
int B = 50;
if (A > B) {
System.out.println("A > B");
}
}
}

package alif;
class DemoIf_Else {
public static void main(String[] args) {
int A = 10;
int B = 50;
if (A > B)
System.out.println("A > B");
else
System.out.println("B > A");
}
}
package alif;
class NestedIF {
public static void main(String args[]) {
int Basics = 10;
int Phys = 90;
int Bio = 90;
if (Basics >= 70) {
System.out.println("Basics passed");
if (Phys >= 70) {
System.out.println("Physics passed");
if (Bio >= 70) {
System.out.println("Bio passed");
}
}
} else {
System.out.println("awas tugas wakakakakak");
}
}
}

package alif;
class MultiConditionIF {
public static void main(String args[]) {
int Basics = 90;
int Phys = 90;
int Bio = 90;
if (Basics > 70 && Phys > 70 && Bio > 70) {
System.out.println("You kill mea?");
}
}
}
package alif;
public class swith {
static int Bulan = 7;
public static void main (String args[]){
switch (Bulan) {
case 1:
System.out.println("Januari");
break;
case 2:
System.out.println("Februari");
break;
case 3:
System.out.println("Maret");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("Mei");
break;
case 6:
System.out.println("Juni");
break;
case 7:
System.out.println("Juli");
break;
case 8:
System.out.println("Agustus");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("Oktober");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("Desember");
break;
default:
System.out.println("Angka yang Anda masukkan salah");
}
}
}

package alif;
public class tenary {
public static void main (String args[]){
int nilaiMatematika = 10;
int nilaiAkhir = 0;
if (nilaiMatematika >= 10)
nilaiAkhir = 1;
else
nilaiAkhir = 0;
System.out.println(nilaiAkhir);
}
}
package alif;
public class tenaryif {
public static void main(String args[]){
int Math = 9;
int Final = 0;
Final = Math >= 10 ? 1 : 0;

System.out.println(Final);
}
}
package alif;
import java.util.Scanner;
public class menghitunghargabarang {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of items: ");
int quantity = input.nextInt();
double pricePerItem;
if (quantity < 100) {
pricePerItem = 10000.0;
} else if (quantity < 150) {
pricePerItem = 9500.0;
} else {
pricePerItem = 9000.0;
}
double totalPrice = quantity * pricePerItem;
System.out.printf("Total price: Rp%,.2f", totalPrice);
}
}
package alif;
import java.util.Scanner;
public class utsdanuas {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter UTS score: ");


double uts = input.nextDouble();

System.out.print("Enter UAS score: ");


double uas = input.nextDouble();
System.out.print("Enter Tubes score: ");
double tubes = input.nextDouble();
double average = (uts + uas + tubes) / 3;
if (average >= 75 && tubes >= 60) {
System.out.println("Congratulations, you passed the course with an average score of
" + average);
} else {
System.out.println("Sorry, you did not pass the course. Your average score is " +
average + " and your Tubes score is " + tubes);
}
}
}

You might also like