Seleksi Bilangan dengan 2 input

Bagaimana proses untuk menentukan bilangan genap ganjil suatu bilangan dengan 2 inputan (inputan nilai awal dan akhir) di Java. berikut kodenya..mudah-mudahan bisa jadi bahan referensi.

/**
*
* @author Administrator
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class bilangan
{
public static void main( String[] args )

throws IOException
{
InputStreamReader inStream =new InputStreamReader(System.in);
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String inputData;

int awal,cek,akhir;

System.out.print("Masukkan nilai awal = ");
inputData=dataIn.readLine();
cek=Integer.parseInt(inputData);

System.out.print("Masukkan nilai akhir = ");
inputData=dataIn.readLine();
akhir=Integer.parseInt(inputData);

for(awal=cek;awal<=akhir;awal++)
{
if((awal % 2)==0)
{
System.out.println("Nilai = "+awal+" Merupakan Bilangan Genap");
}
else
{
System.out.println("Nilai = "+awal+" Merupakan Bilangan Ganjil");
}

}
}
}

Advertisements
Seleksi Bilangan dengan 2 input

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s