package latpengulangangenapganjil;
import java.io.DataInputStream;
public class LatPengulanganGenapGanjil {
public static void main(String[] args) throws Exception
{
DataInputStream data = new DataInputStream (System.in);
System.out.print ("Tentukan Nilai Awal = ");
String awal = data.readLine();
int x = Integer.valueOf(awal).intValue();
System.out.print ("Tentukan Nilai Akhir = ");
String akhir = data.readLine();
int y = Integer.valueOf(akhir).intValue();
System.out.print ("Deret Bilangan ");
for (int a=x; a<y; a++)
{
System.out.print(a+"");
}
System.out.print ("\nDeret Bilangan genap ");
int b = 0;
int d = 0;
for (int a=x; a<y; a++)
{
if (a%2==0)
{
System.out.print(a+"");
d = d+1;
b=b+a;
}
}
System.out.print("\nJumlah bilangan = "+b);
System.out.print("\nBanyaknya bilangan = "+d);
System.out.print ("\nDeret Bilangan ganjil ");
int c =0;
int e = 0;
for (int a=x; a<y; a++)
{
if (a%2!=0)
{
System.out.print(a+"");
e = e+1;
c = c+a;
}
}
System.out.print("\nJumlah Bilangan = "+c);
System.out.print("\nBanyaknya bilangan = "+e);
}
}
Output :
Tidak ada komentar:
Posting Komentar