Share on Google+Share on Google+

Allaa S
Trouble with array manipulation
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners

For this project I have to print 10 random numbers from (0-99), print the max value, the average of the ten numbers, print the first index at which the maximum of the array occurs, and create an array b which has the same values as a only in reverse order, and print out the first 10 values of b. basically the output should be similar to this: Average=47.59 Maximum value=98 Index of maximum=44 First 10 components of b: 71 5 22 57 23 16 14 68 80 23

This is the code i attempted, but i am having trouble putting it together in order to make sence.. any solutions:

import java.util.Random; import java.util.Scanner; public class ArrayRandom{ public static void main(String args[]){ Random r = new Random(); int array [] = new int[100];

    for(int i = 0; i <100; i++){

       array[i] = r.nextInt(100) + 1;
    }
        System.out.println("First 10 components of b: ");
        for(int i = 0; i <10; i++){
       System.out.print(array[i] + " ");
    }
} 
    public int sum( int[] array ){ 
        int sum = 0; 
        for( int i = 0; i < array.length; i++ ){ 
        sum += array[i]; 
    } 
        int average= sum/10;
        System.out.println("Average: "+ average);
        }

        public static void main (String[] args){
            let max = array[0] 
            for(i in array) 
            if i > max 
            max = i

            System.out.println(Math.max(RA); 

        }

}

Ads

View Answers

October 27, 2011 at 12:55 PM


import java.util.Random;

public class ArrayRandom{
    public static void main(String args[]){
        Random r = new Random();
        int array [] = new int[10];
        for(int i = 0; i <array.length; i++){
        array[i] = r.nextInt(100) + 1;
        }

     int sum = 0; 
     int max = array[0];
      int index=0;
        for( int i = 0; i < array.length; i++ ){ 
        sum += array[i]; 
        if( array[i] > max){
            max =  array[i];
            index=i;
        }
    } 
        int average= sum/10;
        System.out.println("Average is: "+ average);
        System.out.println("Maximum Number is: "+ max);
        System.out.println("Index of max number is: "+ index);
        System.out.println("First 10 components of b: ");
        for(int i = array.length-1; i >=0; i--){
        System.out.print(array[i] + " ");
    }
    }
}









Related Tutorials/Questions & Answers:
Trouble with array manipulation
Trouble with array manipulation  For this project I have to print 10..., print the first index at which the maximum of the array occurs, and create an array b which has the same values as a only in reverse order, and print out
array manipulation - Java Beginners
array manipulation  We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array
Advertisements
array manipulation - Java Beginners
array manipulation  Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements. middleWay({1, 2, 3}, {4, 5, 6}) ? {2, 5} middleWay({7, 7, 7}, {3, 8, 0}) ? {7, 8} middleWay
string manipulation
string manipulation  Write a program in java and accept 10 strings form the user. store them in an array. then find the string with the maaximum length and print
Manipulation of war fie contents
Manipulation of war fie contents  How can I manipulate a specific file inside my war file without extracting it? Please help... Thanks and regards, Swapnil
string manipulation in xml
string manipulation in xml  im working on build.xml using apache ant... in one of the targets i am assigning a var file with the full path of .sql files present in a folder. while executing that .sql file in xml its giving me
Image Manipulation in Swing AWT
Image Manipulation in Swing AWT  Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later
Trouble in running Dos Command from Java Servlet
Trouble in running Dos Command from Java Servlet  Hello All, I have to run following command from Java. The command is : vscanwin32 /S C:\Test > C:Scan_Result.txt vscanwin32 is resided at location: C:\Program Files\Trend
Working with CSS(CSS Manipulation)
Working with CSS(CSS Manipulation)       Working with CSS(CSS Manipulation) These methods are used to manipulate CSS specially by getting and setting
Mysql Date Manipulation
Mysql Date Manipulation       Mysql Date Manipulation find out the difference between two values... Date Manipulation. To grasp this example, we create a table 'Person' with field
How to update record to database? I have trouble with the following code
How to update record to database? I have trouble with the following code  I have written the update statement but it still not work to update the record,what is the missing of the following code ?I need help,thankyou <?php
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
could not execute native bulk manipulation query
could not execute native bulk manipulation query  I am insert data in mysql through struts hibernate integration. But above error is coming. Please help me I am sending our Insert Class coding My Insert class coding package
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
Array
Array  How do i insert elements into an array up to a limit from...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size]; System.out.println("Enter Array Elements: "); for(int i=0;i<
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
Array
Array  can we create an array of size 1 lakh in java programming
Data Manipulation Statements
Data Manipulation Statements       Data Manipulation Statement is used to retrieve, insert, update... the following Data Manipulation Statements : Select Statement Insert Statement
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads