Pertemuan 04c

  1. int a=1; int x=0;
    switch(a) {
    case 1: {
    x+=5;
    break;
    }
    case 2: {
    x+=10;
    break;
    }
    case 3: {
    x+=16;
    break;
    }
    case 4: {
    x+=34;
    break;
    }
    }
  2. import java.util.Scanner;

    public class TernOperator{
    public static void main(String[] args){
    Scanner inNilai = new Scanner(System.in);
    int n;
    boolean c;

    do{
    c = true;
    System.out.print(“Input nilai [0..100]: “);
    try{
    n = inNilai.nextInt();
    if(n<0||n>100){
    System.out.println(“Wrong input.”);
    c = false;
    }else{
    if(n>65) System.out.println(“Passed”);
    else System.out.println(“Failed”);
    }
    }catch(Exception e){
    System.out.println(“Input must be a number!”);
    c = false;
    inNilai = new Scanner(System.in);
    }
    }while(!c);
    }
    }

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *