You are viewing a single comment's thread. Return to all comments →
**Can anyone explain why this code is not working, I'm only getting the first "============" line in the output **
import java.util.Scanner; class Convert { String Strconvert(String s1) { int space= 15-s1.length(),i; for(i=0;i
}
String Numconvert(int x) { int i=0,n; do { n=x/10; i++; } while(n>0); if(i==3) { return(Integer.toString(x)); } else { if(i==2) { return("0"+Integer.toString(x)); } else { return("00"+Integer.toString(x)); } }
public class Solution {
public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("================================"); Convert obj = new Convert(); for(int i=0;i<3;i++){ String s1=sc.next(); int x=sc.nextInt(); String s2 = obj.Strconvert(s1); String s3 = obj.Numconvert(x); System.out.println(s2+s3); //Complete this line } System.out.println("================================"); }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Output Formatting
You are viewing a single comment's thread. Return to all comments →
**Can anyone explain why this code is not working, I'm only getting the first "============" line in the output **
import java.util.Scanner; class Convert { String Strconvert(String s1) { int space= 15-s1.length(),i; for(i=0;i
String Numconvert(int x) { int i=0,n; do { n=x/10; i++; } while(n>0); if(i==3) { return(Integer.toString(x)); } else { if(i==2) { return("0"+Integer.toString(x)); } else { return("00"+Integer.toString(x)); } }
}
public class Solution {
}