我正在尝试使用该函数向用户输入的数字添加零printf()。但是,我不确定语法用法。这是我到目前为止所拥有的:
public class Solution {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
final int requiredNumLength = 3;
// readign untill EOF
while (reader.hasNext()){
// getting the word form the input as a string
String word = reader.next();
// getting the number from the input as an integer
int num = reader.nextInt();
int length = String.valueOf(num).length();
if (length < requiredNumLength){
int zerosRequired = requiredNumLength - length;
//System.out.println("required zeros: " + zerosRequired);
}
// print out …Run Code Online (Sandbox Code Playgroud)