Jump to content

Recommended Posts

Posted

Salut!. Am de rezolvat o problema in Java (Dându-se numărul natural n par, determinaţi numerele prime p1 şi p2  (p1 diferit de p2 ) astfel că n  = p1 + p2 (verificarea ipotezei lui Goldbach)). Am nevoie de o rezolvare utilizand doua clase (Numar si Test). Am incercat o rezolvare, dar ma impotmolesc... Oare ma poate ajuta cineva?

// 1
public class Numar {
private long n;

public long getN() {
  return n;
}
public void setN(long n) {
  this.n = n;
}

public boolean Prim (long n){
  long j=2;
  while (j*j<=this.n && this.n%j!=0)
   if (j==2) j=3;
   else j=j+2;
  if (j*j>this.n) return true;
  else   return false;
}

}

//2
public class Test {
public static void Citire (long val){
  System.out.print (val);
}
public static void Afisare (Numar n){
  System.out.print (n.getN());
}
public static void main (String[] args){
  Numar nr = new Numar ();
  for (i = 3; i < (n.getN() / 2); i++) {
   Numar (I)=new Numar (i);
   Numar (NMinI)= new (Numar (n.getN()-i));
   if (Prim(I) && Prim(NMinI)){
   Afisare (I, NMinI);
   }
  }
}
}

Posted

1) Ai postat in zona de javascript :))

 

2)Ce anume nu merge?

 

3) ce inseamna Numar (I)? vad ca ai scris Numar (I)=new Numar (i); .. Sincer nam mai vazut asta , ce inseamna? 

love is a verb
Love is a doing word

Posted

nu trebuie parantezele alea


Numar I = new Numar (i);
Numar NMinI = new Numar (n.getN()-i);

daca mi-ar fi compilat, crede-ma ca nu as mai fi scris aici

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.