Skip to content

Instantly share code, notes, and snippets.

@erikgunawan
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikgunawan/6c1491f215d37b877976 to your computer and use it in GitHub Desktop.
Save erikgunawan/6c1491f215d37b877976 to your computer and use it in GitHub Desktop.
Mencari Nilai dan Jumlah Suku Barisan Aritmatika dengan Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @Developer : Erik Gunawan
* @Nickname : EXz
* @Phone : 0896 5332 0577
* @EMail : admin@erikgunawan.com
* @Gmail : erik.gunawan44@gmail.com
* @Website : www.erikgunawan.com
* @Facebook : facebook.com/revolutionist.exz
* @Twitter : twitter.com/_EXz
*/
public class BarisanDeretAritmatika {
private static BufferedReader br = null;
public static void main(String[] args) {
System.out.println("====================================");
System.out.println("Program Barisan dan Deret Aritmatika");
System.out.println("====================================");
System.out.println();
boolean cek = true;
while (cek) {
br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("Masukkan suku pertama (a) : ");
int a = Integer.parseInt(br.readLine());
System.out.print("Masukkan nilai beda (b) : ");
int b = Integer.parseInt(br.readLine());
System.out.print("Masukkan banyak suku (n) : ");
int n = Integer.parseInt(br.readLine());
System.out.println();
int Un = a + (n-1) * b;
System.out.println("Nilai suku ke-" + n + " (U" + n + ") adalah : " + Un);
int Sn = (a+Un) * n / 2;
System.out.println("Jumlah " + n + " suku pertama (S" + n +") adalah : " + Sn);
System.out.println();
System.out.print("Ingin coba lagi (Y/N) ? ");
String coba = br.readLine();
if (coba.equalsIgnoreCase("N"))
cek = false;
else if (coba.equalsIgnoreCase("Y"))
cek = true;
else
System.exit(0);
}
catch (IOException ioe) {
System.out.println("Error IOException");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment