diff --git a/java/Armstrong.java b/java/Armstrong.java new file mode 100644 index 0000000..ca8f9d8 --- /dev/null +++ b/java/Armstrong.java @@ -0,0 +1,29 @@ +//Program to check whether a number is an armstrong number or not. +//A positive integer is called an Armstrong number of order n if the sum of cubes of each digits is equal to the number itself. + +import java.util.Scanner; + +public class Armstrong { + + public static void main(String[] args) + { + System.out.println("Enter any number: "); + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int m, rem, res = 0; + + m = n; + + while(m!= 0) + { + rem = m % 10; + res+= Math.pow(rem, 3); + m /= 10; + } + + if(res == n) + System.out.println(n + " is an Armstrong number."); + else + System.out.println(n + " is not an Armstrong number."); + } +} \ No newline at end of file diff --git a/java/Median.java b/java/Median.java new file mode 100644 index 0000000..9c2117c --- /dev/null +++ b/java/Median.java @@ -0,0 +1,33 @@ +import java.util.*; +import java.io.*; +import java.lang.*; +class Median +{ + public static void main(String args[]) + { + Scanner sc=new Scanner(System.in); + System.out.println("Enter the number of elements in the array"); + int n=sc.nextInt(); + double[] input=new double[n]; + System.out.println("Enter the elements of the array(" +n+ "): "); + for(int i=0;i