Posts

Showing posts from September, 2017

Sum all the elements of array

Image

Hallow Triangles

     /*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package javaapplication1; import java.util.*; /**  *  * @author Basit  */ public class JavaApplication1 {     /**      * @param args the command line arguments      */     public static void main(String[] args) {         // TODO code application logic here         System.out.println("Salam Pakistan");         Scanner input = new Scanner(System.in);         System.out.print("Plz Enter a number :");         int num = input.nextInt();                         for ( int i=1 ; i<=num; i++ ) {         ...

How to find Factorial in Java Language using method and static variables

public class Factorial { public static void main(String[] args) { final int NUM_FACTS = 100; for(int i = 0; i < NUM_FACTS; i++) System.out.println( i + "! is " + factorial(i)); } public static int factorial(int n) { int result = 1; for(int i = 2; i <= n; i++) result *= i; return result; } }