java - Method doesn't work -


for assignment, have use methods find number of patterns in array. pattern counted when sum of adjacent numbers in array more 7.

i have use 2 methods, 1 being insertnumbers create array , being computepattern count patterns.

however, pattern printed out doesn't match array printed out. here code.

as assignment, rather not answers answers on part of code wrong, , how fix it.

edit: here sample output.

sample output #1: array: 2 7 2 3 1 5 7 4 3 6

number of patterns: 3

public static int[] insertnumbers() {     //declaring array.     int randomarray[] = new int[10];      //setting random numbers array.     (int k = 0;k < randomarray.length;k++)     {         int = (int)((math.random()*9)+1);         randomarray[k] = i;     }      //returning array other methods.     return randomarray; }  public static int computepattern() {     int = 0;     int b = 1;     int pattern = 0;     int[] randomarray = insertnumbers();     //computing number of patterns.     (;a<=8 && b<=9;)     {         if (randomarray[a] + randomarray[b]>7)         {             pattern++;                     }               a+=2;         b+=2;     }     return pattern; }  public static void main(string[] args)  {     int pattern = computepattern();     int[] randomarray = insertnumbers();      //printing out contents of array.     system.out.print("array : " );     for(int = 0; < 10; i++)     {         system.out.print(+randomarray[i] +" ");     }      system.out.println(" ");      //printing out number of patterns.     system.out.println("number of patterns: "+pattern); } 

you computing pattern different array, , in main printing different array (you calling insertnumbers twice basically). see here:

    int pattern = computepattern(); // first time computepatter generates 1 array     int[] randomarray = insertnumbers(); // array generated here 

also, doesn't seem pattern counting correct. hint: compare elements indexes 1 , 2?


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -