Postingan

Menampilkan postingan dari 2018

Program Pola Bintang menggunakan Java

Segitiga siku-siku kanan import java.util.Scanner; public class BintangSikuKanan { public static void main(String args[]) { Scanner db=new Scanner(System.in); System.out.println("Masukkan batas baris: "); int n=db.nextInt(); /*int n=5;*/ for (int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { System.out.print("*"); } System.out.println(); } } } Segitiga siku-siku kiri import java.util.Scanner; public class BintangSikuKiri { public static void  main(String []args) { Scanner db=new Scanner(System.in); System.out.println("Masukkan batas baris: "); int n=db.nextInt(); int i,j,k; for( i=1;i<=n;i++) { //spasi for( j=(n-1);j>=i;j--) { System.out.print(" "); } for( k=1;k<=i;k++) { System.out.print("*"); } System.out.println(); } } } Segitiga sama sisi import java.util.Scanner; public class BintangSegitigaSamaSi

HACKER RANK SOLUTIONS : Simple Array Sum

Given an array of integers, find the sum of its elements. For example, if the array  ,  , so return  . Function Description Complete the  simpleArraySum  function in the editor below. It must return the sum of the array elements as an integer. simpleArraySum has the following parameter(s): ar : an array of integers Input Format The first line contains an integer,  , denoting the size of the array. The second line contains   space-separated integers representing the array's elements. Constraints Output Format Print the sum of the array's elements as a single integer. Sample Input 6 1 2 3 4 10 11 Sample Output 31 Explanation We print the sum of the array's elements:  .S Solution  : import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class SimpleArraySum {     public static void main(String[] args) {         Sca