Results 1 to 2 of 2
  1. #1
    psp300xxx is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default problem with an exercise

    Hi, i'm new in this forum...
    i've a problem with an exercise in java, this is request to me:
    Esercizio 2
    Esercizio 2
    Si scriva un metodo java
    estrai
    che riceve un vettore di interi
    a
    e restisce un vettore
    b
    contenente i numeri primi
    x
    che
    compaiono in
    a
    tali che: 1)
    x
    il primo elemento di
    a
    oppure 2)
    x
    minore di tutti gli elementi che lo precedono in
    a
    . Ad
    esempio se
    a
    =[13,8,6,5,7,10,3] allora
    b
    =[13,5,3]


    and this is my code...:


    import java.util.*;

    public class esesame{
    public static void main(String [] args){
    System.out.println("Facciamo questo esercizio");
    int [] x= {13,8,6,5,7,10,3};
    int [] y= null;
    y= vettusc(x);

    }

    public static int [] vettusc(int [] m){
    int [] q = null;
    int cont=0;
    int cont1=0;
    int i;
    for (i=0; i<m.length; i++){
    if ( numprimo(m[i]) && primel(m, m[i]) || nummin(m, m[i]) ){cont++;}
    }
    q=new int [cont];
    for (int j=0; j<m.length; j++){
    if ( numprimo(m[i]) && primel(m, m[i]) || nummin(m, m[i]) ){q[cont1]=m[j];cont1++;}
    }
    return q;
    }

    public static boolean numprimo(int x){
    int r=0;
    for (int i=x-1; i>1; i--){
    r=x%i; if(r==0){return false;}
    }
    return true;
    }

    public static boolean primel(int [] m, int x){
    if (m[0]==x){return true;}
    return false;
    }

    public static boolean nummin(int [] m, int x){
    int p=indice(m,x);
    for( int i=0; i<p; i++){
    if (m[i]<x){return false;}
    }return true;
    }

    public static int indice(int [] m, int x){
    for(int i=0; i<m.length; i++){
    if (m[i]==x){return i;}
    }
    return -1;

    }

    }


    so what's the problem?

  2. #2
    psp300xxx is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Problem with BlueJ Exercise
    By TomFahey in forum New To Java
    Replies: 4
    Last Post: 05-29-2013, 05:44 PM
  2. Problem with an exercise in java
    By chkontog in forum New To Java
    Replies: 2
    Last Post: 11-19-2012, 12:46 PM
  3. Problem in an exercise
    By Honest989 in forum New To Java
    Replies: 1
    Last Post: 11-10-2010, 09:08 PM
  4. Exercise problem, how was this output achieved?
    By bs3ac in forum New To Java
    Replies: 8
    Last Post: 08-06-2010, 02:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •