import java.util.*;
public class Solution {
public static void main(String[] args) {
String s=" ";int j=0,len=0;
Scanner sc = new Scanner(System.in);
System.out.println("================================");
for(int i=0;i<=2;i++)
{
s=sc.nextLine();
j=sc.nextInt();
len=s.length();
System.out.print(s);
for(int k=(16-(len+1));k>=1;k--)
{
System.out.print(' ');
}
if(j>=100 && j<=999)
{
System.out.println(j);
}
else if(j<=100)
{
System.out.println("0"+j);
}
else if(j<=9)
{
System.out.println("00"+j);
}
}
System.out.println("================================");
sc.close();
}
}```
#need help in hackerrank question
37 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @torn bloom! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
??
bro
actuallythis is the question
but i found a online solution in just 1 line
System.out.printf("%-15s%03d\n", s1, x);
what does this line means may u explain?
%-15s means format string specifies that the first argument, s1, should be left-justified in a field that is 15 characters wide!
and padded with spaces to fill the field if necessary
and how this line auto adds 0 befor int if it is not of 3 digit?
%03d part of the format string specifies that the second argument, x, should be formatted as a decimal integer with at least three digits, padded with leading zeros!
oo still i have not studied printf
goodluck!
??
what do you think?
from my understanding i think we should print a+2 to the power 0 to the number provided(which is n)*b
for (int j = 0; j < n; j++) {
int x = (int) Math.pow(2, j);
s = a + x * b;
}```
like this?
dont do hacker rank yet if you can't solve it without a lot of help
That's not it
Did you study AP? It's an AP question
Maybe
Not AP but progression fs
noo idk
yeah i also think so i should stop solving hacker rank
not disrespecting or all this stuff is not good for practice when starting off
thats TRUE!
Yeah I agree, but there's also a point when you can just zoom right through most questions. That kinda defeats the purpose. You'll have to just find the right time per your needs and conditions