Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

simple intro to java problem . please use only loops no arrays. thanks! Coding A

ID: 3691393 • Letter: S

Question

simple intro to java problem . please use only loops no arrays. thanks!

Coding Assignment. Numeric Palindromes A three digit numeric palindrome is a series of three numbers that start and end with the same digit. IE 131, 222, 606 are all numeric palindromes. 123, 890, 936 are not numeric palindromes. Your assignment is to prompt the user for two numbers. You will multiply these numbers together, and Find all three digit palindromes contained in the larger number. IE if le product of the two numbers was 3459592 the palindromes would be: 595, 959 Print out the sum of the two digits, and each palindrome you Find in the sum. If there are no palindromes - print a message "None Found"; Note - It would be wise to use a longs to store your numbers and your product.

Explanation / Answer

PalindromeCheck.java


import java.util.Scanner;

public class PalindromeCheck {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner scan = new Scanner(System.in);
       System.out.println("Please enter the first value");
       int first = scan.nextInt();
       System.out.println("Please enter the second value");
       int second = scan.nextInt();
       long product = first * second;
       String productStr= String.valueOf(product);
       System.out.println("The product of two numbers is "+product);
       boolean found = false;
       String str1 ="", str2 = "";
       for(int i=0; i<productStr.length()-2; i++){
str1 = productStr.substring(i, i+2);
//System.out.println(str1);
str2 = productStr.substring(i+1, i+3);
//System.out.println(str2);
if((Integer.parseInt(str1.charAt(0)+"")+Integer.parseInt(str1.charAt(1)+"")) == (Integer.parseInt(str2.charAt(0)+"")+Integer.parseInt(str2.charAt(1)+""))){
   found = true;
   System.out.println(productStr.substring(i, i+3));
}
  
}
       if(!found)
           System.out.println("None Found");
   }

}

Output:

Please enter the first value
864898
Please enter the second value
4
The product of two numbers is 3459592
959
595