/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package binergajilgenap;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/**
*
* @author andi m
*/
public class BinerGajilGenap {
/**
* @param args the command line arguments
*/
public static void main ( String [] args ) throws IOException{
Scanner input=new Scanner(System.in);
System.out.print ( "Masukan Bilangan Binernya = " ) ;
String str = input.nextLine();
long num = Long.parseLong(str) ;
long rem;
while ( num > 0 ){
rem = num % 10 ;
num = num / 10 ;
if ( rem != 0 && rem != 1 ){
System.out.println ( "Ini bukan bilangan biner." ) ;
System.out.println ( "Silahkan Coba lagi" ) ;
System.exit ( 0 ) ;
}
}
int i= Integer.parseInt ( str,2) ;
if(i%2==0){
System.out.println("Genap");
}
else{
System.out.println("Ganjil");
}
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package binergajilgenap;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/**
*
* @author andi m
*/
public class BinerGajilGenap {
/**
* @param args the command line arguments
*/
public static void main ( String [] args ) throws IOException{
Scanner input=new Scanner(System.in);
System.out.print ( "Masukan Bilangan Binernya = " ) ;
String str = input.nextLine();
long num = Long.parseLong(str) ;
long rem;
while ( num > 0 ){
rem = num % 10 ;
num = num / 10 ;
if ( rem != 0 && rem != 1 ){
System.out.println ( "Ini bukan bilangan biner." ) ;
System.out.println ( "Silahkan Coba lagi" ) ;
System.exit ( 0 ) ;
}
}
int i= Integer.parseInt ( str,2) ;
if(i%2==0){
System.out.println("Genap");
}
else{
System.out.println("Ganjil");
}
}
}
No comments