Sabtu, Oktober 15, 2011

Faktorial (FOR)



Pada kali ini saya mencoba membuat Contoh Program menggunakan For :

import java.util.Scanner;
public class ProgramFor
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
int f=5; //nilai yang ditampilkan pada hasil
System.out.printf("Masukan Nilai m = ");
int m= in.nextInt();
System.out.printf("Masukan Nilai n = ");
int n= in.nextInt();
System.out.println("========================= ");
System.out.print("Hasil = ");
for (int i=m; i<=n; i++)
if(i%2==0)
System.out.print(" "+i+",");
else
f+=i;
System.out.println("\nJumlah = "+f);
System.out.println("========================= ");
}
}


• Output-nya dapat dilihat pada gambar dibawah ini.



 

Saldeath Blak Magik is Designed by productive dreams for smashing magazine Bloggerized by Ipiet © 2008 | Free Blogger Theme | Free Ebooks