In Java. Write a method with the following header to format the integer with the specified width. public String format(int number, int width) The method returns a string for the number with one or more prefix 0s. The size of the string is the width within the range [1 to 10000]. For example, format(34, 4) returns 0034 and format(34,5) returns 00034. If the number is longer than the width, the method returns the string representation for the number. For example, format(34, 1) returns 34. Assume that, the size of the string is the width within the range [1 to 10000] and the number is an integer [-2147483647, 2147483647 ] You can assign tasks to multiple private methods. Input: 34 4 Output: 0034 ------------------------ Input: 34 1 Output: 34 Some Notes: 1- if the number of digits of the "number" is less than requested zeros, you need to add zero to the output, for example Input: 0 4 Output: 0000 2- Test your code for large numbers and also negative numbers as well. Input: -2147483647 10 Output: -2147483647 3- Test your code for large number of zeros also.
In Java.
Write a method with the following header to format the integer with the specified width.
public String format(int number, int width)
The method returns a string for the number with one or more prefix 0s. The size of the string is the width within the range [1 to 10000]. For example, format(34, 4) returns 0034 and format(34,5) returns 00034. If the number is longer than the width, the method returns the string representation for the number. For example, format(34, 1) returns 34.
Assume that, the size of the string is the width within the range [1 to 10000] and the number is an integer [-2147483647, 2147483647 ]
You can assign tasks to multiple private methods.
Input:
34
4
Output:
0034
------------------------
Input:
34
1
Output:
34
Some Notes:
1- if the number of digits of the "number" is less than requested zeros, you need to add zero to the output, for example
Input:
0
4
Output:
0000
2- Test your code for large numbers and also negative numbers as well.
Input:
-2147483647
10
Output:
-2147483647
3- Test your code for large number of zeros also.
public String format(int number, int width)
The method returns a string for the number with one or more prefix 0s. The size of the string is the width within the range [1 to 10000]. For example, format(34, 4) returns 0034 and format(34,5) returns 00034. If the number is longer than the width, the method returns the string representation for the number. For example, format(34, 1) returns 34.
Assume that, the size of the string is the width within the range [1 to 10000] and the number is an integer [-2147483647, 2147483647 ]
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images