-[Java] Mencari nilai suku ke-n

-[Java]  Praktikum 2 : Mencari nilai suku ke-n- ini merupakan lanjutan dari postingan : ALGORITMA DAN PEMROGRAMAN MODUL 1 SUB PROG...

-[Java] Praktikum 2 : Mencari nilai suku ke-n-
ini merupakan lanjutan dari postingan :

ALGORITMA DAN PEMROGRAMAN

MODUL 1 SUB PROGRAM (Procedure & Function).


b. Praktikum 2 :


import java.util.Scanner;
import java.math.*;
public class Contoh2
{
//function, krn ada tipe data utk funsi rasio dan return
static int rasio(int a, int b)
{
return (b/a);
}
static int sukuN(int r, int n, int a)
{
//Math.pow() method utk pemanggilan fungsi perpankatan
//cara penggunaannya:
//(tipeData) Math.pow (bil yg dipangkatkan, bil pemangkat)
return ((int) Math.pow((a*r),(n-1)));
}
public static void main (String[] args)
{
Scanner data = new Scanner(System.in);
System.out.print("Masukkan suku ke-1: ");
int suku1 = data.nextInt();
System.out.print("Masukkan suku ke-2: ");
int suku2 = data.nextInt();
int d = rasio(suku1,suku2);
System.out.print("Rasionya adalah: " + d);
System.out.print("\nMasukkan n untuk mencari nilai suku ke-n: ");
int sukun = data.nextInt();
System.out.println("Maka nilai suku ke-" + sukun + " adalah: "+sukuN(d, sukun, suku1));
}
}
Hasil Outputnya :

 



Demikian contoh  Pratikum (Procedure dan Function). semoga bermanfaat.


COMMENTS

BLOGGER

Nama

Artikel,66,Cerita singkat,82,Java,12,SEO,15,Tahukah sobat??,21,Tips dan Trik,15,Tips.....n' Trick.....,14,Tutorial,20,Tutorial Blogger,50,
ltr
item
Blog Salman Syuhada: -[Java] Mencari nilai suku ke-n
-[Java] Mencari nilai suku ke-n
https://4.bp.blogspot.com/-BkHYtO3Hn34/T8HOOc31yWI/AAAAAAAABTA/Ydw6TrS1Qz8/s1600/java.jpeg
https://4.bp.blogspot.com/-BkHYtO3Hn34/T8HOOc31yWI/AAAAAAAABTA/Ydw6TrS1Qz8/s72-c/java.jpeg
Blog Salman Syuhada
http://blog.salmansyuhada.com/2012/05/praktikum-2.html
http://blog.salmansyuhada.com/
http://blog.salmansyuhada.com/
http://blog.salmansyuhada.com/2012/05/praktikum-2.html
true
5369818979434965955
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy