Summe die Produkte von Zahlen im Bereich dass Ziffern Primzahl sindJava

Java-Forum
Anonymous
 Summe die Produkte von Zahlen im Bereich dass Ziffern Primzahl sind

Post by Anonymous »

Ich habe ein kleines Problem - ich muss das Programm vorbereiten, das (Schritt -für -Schritt -Informationen):

1) von Benutzern zwei Ganzzahlen A und b erhält und stoppen Sie, wenn B >

Code: Select all

a
2)Sum the products off all numbers in range < a, b > that digits are prime numbers

Example:

Input: 10, 15,

Output: 2340
(because 12*13*15 = 2340
2, 3 and 5 are prime Zahlen < /strong>) < /p>

Ich fühle mich wie ich festgefahren - ich habe nur eine Summe der Zahlen (nicht das Produkt) und nicht die Primzahl, sondern alle von ihnen. < /p>

Code: Select all

public class Ex4 {
static int getNmbs() {
System.out.println("Enter number:");
Scanner sc = new Scanner(System.in);
return sc.nextInt();
}
public static int getSum(int a, int b) {
if (a > b)
return 0;
else
return a + getSum(a + 1, b);
}

public static void main(String[] args) {
int a = getNmbs();
int b = getNmbs();
int c =getSum(a,b);
System.out.println(c);
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post