Problem Description Find all numbers that when multiplied by

Problem Description

Find all numbers that when multiplied by 365 produce an eight digit product where the first four digits of that product are equal to the last four digits of that product. For example, 271123 time 365 produces an eight digit product (98959895) whose first four digits (9895) are equal to its last four digits (9895).

Input/Output

There is no input for this problem.

The output will be a list of the first ten integers that when multiplied by 365 create an eight digit product where the first four digits of that product are equal to the last four digits of that product. Also print the product of the number and 365. Submit a second version of your application that prints all the numbers (not just the first ten) so the judges can see the last ten numbers generated.

Sample Output

Output for a single random combination is listed below.

Number        Number * 365

......        ........

271123        98959895

......        ........

Solution

First Version:-


public class Product {
  
   public static void main(String a[]){
       int count=0;
       StringBuilder sb;
       /*Loop is started randomly from 10000, because product of no number below that with 365 would be of 8 digits */
       for(int i=10000;(i*365)<100000000; i++){
           if(i*365<10000000){
               //if product is less than 8 digits, we don\'t consider it
               continue;
           }
           else{
               sb = new StringBuilder();
               sb.append(\"\");
               sb.append((i*365));
               String strI = sb.toString();
              
               if(strI.substring(0, 4).equals(strI.substring(4))){
                   count++;
                   System.out.println(\"Number \\t \" + \"Number*365\");
                   System.out.println(\"\"+i+ \"\\t\" + (i*365) );
                   if(count==10){
                       break;
                   }
               }
           }
       }
   }
}

Second Version:-


public class Product {
  
   public static void main(String a[]){
       StringBuilder sb;
       /*Loop is started randomly from 10000, because product of no number below that with 365 would be of 8 digits */
       for(int i=10000;(i*365)<100000000; i++){
           if(i*365<10000000){
               //if product is less than 8 digits, we don\'t consider it
               continue;
           }
           else{
               sb = new StringBuilder();
               sb.append(\"\");
               sb.append((i*365));
               String strI = sb.toString();
              
               if(strI.substring(0, 4).equals(strI.substring(4))){
                   System.out.println(\"Number \\t \" + \"Number*365\");
                   System.out.println(\"\"+i+ \"\\t\" + (i*365) );
               }
           }
       }
   }
}

Hey, please drop a message in case of any doubt.

Problem Description Find all numbers that when multiplied by 365 produce an eight digit product where the first four digits of that product are equal to the las
Problem Description Find all numbers that when multiplied by 365 produce an eight digit product where the first four digits of that product are equal to the las

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site