Sabtu, 17 September 2022

Java Dasar 19 - Latihan Operasi Logika

Java Dasar 19 - Latihan Operasi Logika


package com.example;

import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
  
  // latihan tebak angka
 Scanner inputUser = new Scanner(System.in);
 int nilaiBenar = 6;
 int nilaiInputUser;
 boolean statusTebakan;
 
 
 System.out.print("Tebak angka 10 - 4 = \n");
 nilaiInputUser = inputUser.nextInt();
 System.out.println(nilaiInputUser);
 
 // operasi logika
 statusTebakan = (nilaiInputUser == nilaiBenar);
 System.out.println("Jawaban kamu " + statusTebakan);
 
 // operasi aljabar boolean (AND / OR)
 System.out.print("Masukan nilai di antara 4 dan 9");
 nilaiInputUser = inputUser.nextInt();
 statusTebakan = (nilaiInputUser > 4) && (nilaiBenar < 9);
 System.out.println(statusTebakan);
  
  }
}