Anzeige
Please help me on this problem with only using import java-util-Scanne.docx
Please help me on this problem with only using import java-util-Scanne.docx
Please help me on this problem with only using import java-util-Scanne.docx
Nächste SlideShare
How do I fix this intellij java program-  import java-util-Scanner- pu.pdfHow do I fix this intellij java program- import java-util-Scanner- pu.pdf
Wird geladen in ... 3
1 von 3
Anzeige

Más contenido relacionado

Similar a Please help me on this problem with only using import java-util-Scanne.docx(20)

Más de rtodd19(20)

Anzeige

Please help me on this problem with only using import java-util-Scanne.docx

  1. Please help me on this problem with only using import java.util.Scanner;. I'm not certain on how to approach this problem as I keep running to multiple errors. Thanks. Solution import java.util.Scanner; public class MenuDriven { public static void main(String args[]) { int startingPoint = 1, startingPrime = 2, ch, n; final int printPerLine = 10; Scanner s = new Scanner(System.in); System.out.println("enter the choice among the menu "); System.out.println("1.Display prime palindromes 2.display mirrored primes 3.exit prgrm "); ch = s.nextInt(); switch (ch) { case 1: IsItPrime(startingPrime); IsItPalin(startingPrime); System.out.println("enter the number upto which prim pal are to be displayed "); n = s.nextInt(); while (startingPoint <= n) { if (IsItPrime(startingPrime) && IsItPalin(startingPrime)) { System.out.print(startingPrime + " "); if (startingPoint % printPerLine == 0) { System.out.println(); } startingPoint++; }
  2. startingPrime++; } break; case 2: startingPoint = 1; startingPrime = 2; System.out.println("enter the number upto which prim pal are to be displayed "); n = s.nextInt(); while (startingPoint <= n) { if (IsItPrime(startingPrime) && !IsItPalin(startingPrime)) { int rev=reverseNumber(startingPrime); if(IsItPrime(rev)){ System.out.print(startingPrime + " "); } if (startingPoint % printPerLine == 0) { System.out.println(); } startingPoint++; } startingPrime++; } break; case 3: exit(0); } } public static boolean IsItPrime(int sPrime) { if (sPrime % 2 == 0 && sPrime != 2) { return false; } int sqrtPrime = (int) Math.sqrt(sPrime); for (int i = 3; i <= sqrtPrime; i += 2) { if (sPrime % i == 0) { return false; } } return true; }
  3. public static boolean IsItPalin(int sPrime) { int sPrimeBackup = sPrime; int reverse = 0; while (sPrime > 0) { reverse = reverse * 10 + sPrime % 10; sPrime = sPrime / 10; } return (sPrimeBackup == reverse); } public static int reverseNumber(int number){ int reverse = 0; while(number != 0){ reverse = (reverse*10)+(number%10); number = number/10; } return reverse; } }
Anzeige