Question
Do this problem using two integers with either 3, or 4, or 5-digit. The two numbers might not have the same digits length. Please use
Do this problem using two integers with either 3, or 4, or 5-digit. The two numbers might not have the same digits length. Please use only one single loop with one System.out.printf statement for printing the shifted multiplicands as shown in the example below. Please name the class name as PrintMultipOfNDigits.
import java.util.*; public class PrintMultipOfNDigits{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("what's first (3~5)digits :"); int firstnum = in.nextInt(); //set first digit System.out.println("what's second (3~5)digits :"); int secondnum = in.nextInt(); //set second digit int l1= (secondnum%10)*firstnum; //getting first line by module 10 and times first digit so like first digit time last second digit. int l2= ((secondnum%100)/10)*firstnum;//getting second line by module 100 and divide by 10 and then time first digit time 10. int l3= ((secondnum%1000)/100)*firstnum;// getting third line by module 1000 and divide by 100 and then time first digit time 100. int l4= ((secondnum%10000)/1000)*firstnum; int l5= ((secondnum%100000)/10000)*firstnum; int answer = l1+l2+l3+l4+l5; System.out.printf(" %d * %d -------------- %d %d %d %d %d -------------- %d ",firstnum,secondnum,l1,l2,l3,l4,l5,answer); }
}
I am having trouble with this problem help me please. this is code i got until now.
5903multiplicand 178 multiplier 47224 shifted multiplicands 413210 +590300 1050734 productStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started