Bilangan Ganjil Genap
BIASA
package ganjilgenap;
import javax.swing.JOptionPane;
public class SoalTugas {
public static void main(String[]args){
int bil=0;
String
Status="";
System.out.print("inputkan bilangan bulat:");
Status=JOptionPane.showInputDialog("inputkan
bilangan:");
bil=Integer.parseInt(Status);
Status=(bil%2==0)?"Genap":"Ganjil";
System.out.print(Status);
}
}
GANJIL GENAP BOX
package ganjilgenap;
import javax.swing.JOptionPane;
public class SoalTugas {
public static void main(String[]args){
int bil=0;
String
Status="";
Status=JOptionPane.showInputDialog("inputkan bilangan:");
bil=Integer.parseInt(Status);
Status=(bil%2==0)?"Genap":"Ganjil";
System.out.print(Status);
}
}
Memakai Scanner
package ganjilgenap;
import java.util.*;
public class scann1 {
public static void
main(String[]args){
int bil=0;
String
Status="";
Scanner sc = new
Scanner(System.in);
System.out.print("inputkan bilanngane?");
bil=sc.nextInt();
Status=(bil%2==0)?"Genap":"Ganjil";
System.out.print(Status);
}
}
}}
0 komentar:
Posting Komentar