arrays - Method return Java assignment -


okay here's java assignment i've been having trouble with. asked earlier , got comments , advice, have since understood assignment more , issue has changed bit. here's assignment:

                                        *** 

your task complete program below writing 3 methods (askinfo, copyinfo , setarray). program should ask integers (max 100 integers) until users types in zero. integers can vary 1 one hundred , stored in array has 100 elements. numbers asked askinfo method, receives array numbers parameter. method returns number of integers. number 0 not saved in array; merely used stop giving input. given numbers copied array size amount of given numbers. copying done copyinfo method receives both arrays parameters. after elements of new array put in ascending order setarray method , printed on screen printarray method.

program complete:

import java.util.*;

public class revisionexercise {

public static void main(string[] args) {        int[] temparray = new int[100];      system.out.println("type in numbers. type 0 quit.");      int amountofnumbers = askinfo(temparray);        int[] realarray = new int[amountofnumbers];      copyinfo(realarray, temparray);        setarray(realarray);        printarray(realarray);  }   // code here   public static void printarray(int[] realarray ) {      system.out.println("\ordered array: ");      for(int = 0; < realarray .length; i++) {          system.out.println(realarray [i]);      }  } 

example print:

type in numbers. type 0 quit. 1. number: 3 2. number: 8 3. number: 5 4. number: 6 5. number: 9 6. number: 0

ordered array: 9 8 6 5 3


i'm struggling askinfo method. far i've written returns zeroes. here's askinfo method:

public static int askinfo(int[] temparray) { //askinfo-metodi

    scanner reader = new scanner(system.in); 

int i;

    (i = 0; < temparray.length; i++) {          system.out.print((i+1) + ". number: ");         temparray[i] = reader.nextint();      if (temparray[i] == 0) {     return temparray[i];         }       }      return temparray[i];  }                              *** 

how can make register input , amount of numbers passed next method in assignment described in assignment.

you never store integer luku values in array, array never changes default initialized integer values of zeroes. inside loop, need add an

tempa[i] = luku; 

after if-statement confirms luku not 0. in all:

if (luku == 0) {     return i;    } tempa[i] = luku; 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -