shekhar dipti
java
1 Answer(s)      5 years and 4 months ago
Posted in : Java Beginners
A one dimensional array contains 100 element. Each element is an integer.
write a program to read the array and find the mean element of the array
Find the position of the element which has the maximum deviation from the mean




Advertisement
View Answers

January 14, 2010 at 12:12 PM


Hi Friend,

Try the following code:

import java.util.*;
class MaximumDeviation {
public static void main(String[] args){
int max=0;
int j=0;
int sum=0;
int arr[]=new int[100];
Random r=new Random();
for (int i = 0; i < 100; i++){
arr[i]=r.nextInt(100);
System.out.println( arr[i] );
sum+=arr[i];
while(arr[i]>max)
{
max=arr[i];
j=i;
}
}
int mean=sum/arr.length;
System.out.println("Sum: "+sum);
System.out.println("Mean: "+mean);
if(max>mean){
System.out.println("Maximum Number: "+max);
System.out.println("Its Position is: "+j);
}

}
}

Thanks









Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  is java purely object oriented language
java
java  how use java method
java
java  write a program in java to acess the email
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  sample code for RARP using java
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  send me java interview questions
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java