Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions java/Armstrong.java
Original file line number Diff line number Diff line change
@@ -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.");
}
}
33 changes: 33 additions & 0 deletions java/Median.java
Original file line number Diff line number Diff line change
@@ -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<n;i++)
{
input[i]=sc.nextDouble();
}
double res = calcMedian(n,input);
System.out.println("The median of the array is : " + res);
}
static double calcMedian(int n, double arr[])
{
double k=0;
if(n%2==1)
{
k = arr[((n+1)/2)-1];
}
else
{
k = (arr[n/2-1]+arr[n/2])/2;
}
return k;
}
}