Question

123 246 x 738 492 246 30258

Do this problem using two integers with either 3, or 4, or 5-digit. The two numbers might not have the same digit’s length. Please use only one single loop with one System.out.printf statement for printing the shifted multiplicands as shown in the

Please use only one single loop with one System.out.printf statementPlease use only one single loop with one System.out.printf statementPlease use only one single loop with one System.out.printf statement

0 0
Add a comment Improve this question Transcribed image text
Answer #1


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Surya
*/
public class PrintMultipOfNDigits {
  
  
public static void main(String argv[])
{
int n,m,k;
Scanner sc= new Scanner(System.in);
  
System.out.print("Enter two numbers:");
String s1,s2;
s1=sc.next();
s2=sc.next();
  
int n1=s1.length();//for padding
int n2=s2.length();//for padding
n = Integer.parseInt(s1);
m = Integer.parseInt(s2);
  
  
  
k=m;
int c=0,r;
String s=" ",p;
  
while(m>0)//single loop
{
r=m%10;
int l=n*r;
String rr= Integer.toString(l);
if(c==0)
{

p=" "+s.substring(0,s.length()-n1) +n+"\nX"+s.substring(0,s.length()-n2) +m+"\n----------------\n "+s.substring(0,s.length()-rr.length())+rr+"\n";
c++;
s=s.substring(0,s.length()-rr.length());
}
else
{
s=s.substring(0,s.length()-1);
p=" "+s+l+"\n";
}
  
m=m/10;
if(m==0)
{
  
p=p+"----------------\n "+s+n*k+"\n";

}
System.out.printf(p);//single print statement
}
  
}
}

output:

run:
Enter two numbers:5903 178
5903
X 178
----------------
47224
41321
5903
----------------
1050734
BUILD SUCCESSFUL (total time: 2 seconds)

Add a comment
Know the answer?
Add Answer to:
Do this problem using two integers with either 3, or 4, or 5-digit. The two numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assume that you select two 4-digit numbers at random from the set of consecutive integers from...

    Assume that you select two 4-digit numbers at random from the set of consecutive integers from 0000 through 9999. The selections are made with replacement and are independent of one another. If the two numbers are the same, you make $650. If they are different, you lose $4. A random variable XX is defined as your gain or loss.

  • Digit to WordsWrite a C program that asks the user for a two-digit number, then prints...

    Digit to WordsWrite a C program that asks the user for a two-digit number, then prints the English wordfor the number. Your program should loop until the user wants to quit.Example:Enter a two-digit number: 45You entered the number forty-five.Hint: Break the number into two digits. Use one switch statement to print the word for the firstdigit (“twenty,” “thirty,” and so forth). Use a second switch statement to print the word for thesecond digit. Don’t forget that the numbers between 11...

  • 1. Write a program that asks the user to enter two integers, obtains the numbers from...

    1. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.

  • Write a machine language program to input two one-digit numbers ranging from 0 to 4 (using...

    Write a machine language program to input two one-digit numbers ranging from 0 to 4 (using the character input instruction), add them, and then output the single digit sum (using the character output instruction). Execute your program in the PEP/8 simulator. Example Input: 43 (this is the numbers 4 and 3. Remember, this is two ASCII characters when inputted into your program) Output: 7 (ASCII character 55dec)

  • 3. Write a program to read a (binary) file of integers, sort the integers, and write...

    3. Write a program to read a (binary) file of integers, sort the integers, and write them back to the same file. Assume that all the numbers can be stored in an array. (Exercise 3) 4. Repeat exercise 3, but assume that only 20 numbers can be stored in memory (in an array) at any one time. Hint: you will need to use at least two additional files for temporary output. Please finish the question in C language programming, thank...

  • Emergency please!!!! Last two numbers digit: 11 1) (35 pts) In this problem the last two...

    Emergency please!!!! Last two numbers digit: 11 1) (35 pts) In this problem the last two digits of your student number will be important. Let n, be a number equal to the last digit of your student number, na be a number equal to the last two digits of your student number. That is, if the last two digits of your student number is 83 then, n = 3, n2 = 83. Consider the predator-prey equations: dx =ax - bxy...

  • Write a program to subtract large unsigned integers. Your program should prompt and read in two...

    Write a program to subtract large unsigned integers. Your program should prompt and read in two large unsigned integers. The two large integers should be stored arrays, one array for each integer. The integers should be stored with one digit per location in the two arrays. The first integer should be no smaller than the second. Your program should subtract the second integer from the first. The result should be stored in an array, again one digit per location in...

  • This is programming project 1 chapter 9(Book ISBN:1292222824 (1-292-22282-4) Walter Savitch Problem Solving with C++: Global...

    This is programming project 1 chapter 9(Book ISBN:1292222824 (1-292-22282-4) Walter Savitch Problem Solving with C++: Global Edition, 10/E) Question Do Programming Project 7 in Chapter 7 using a dynamic array. In this version of the problem, use dynamic arrays to store the ditits in each large integer. Allow an arbitrary number of digits instead of capping the number of digits at 20. TER 7/ Arrays time. For example digit at a the integer 1234 could be stored in the array...

  • Consider the following problem: given n positive integers, separate them into two groups such that adding...

    Consider the following problem: given n positive integers, separate them into two groups such that adding all the numbers in one group gives the same result as adding all the numbers in the other group. For example, if the numbers are 1, 2, 3, 4, then the two groups could be {1, 4} and {2, 3}, which both sum to 5. For another example, if the numbers are 5, 6, 11, then the two groups could be {5, 6} and...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT