Question: This is a Java program Write a method with the following header to format the integer with the specified width. public String format(int number, int
This is a Java program
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 10000inclusive. 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 inclusive and the number is an integer -2147483648 to 2147483648 inclusive.
Input 34 4
Output 0034
You must use this particular Driver class
class DriverMain{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int num = Integer.parseInt(input.nextLine().trim());
int width = Integer.parseInt(input.nextLine().trim());
GW6_P5 gw6P5 = new GW6_P5();
System.out.print(gw6P5.format(num,width));
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
