Please tell the error in my program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Please tell the error in my program

i have to make a pattern like this 12345 12341 12342 12343 12345 and i am getting problem in my program where the last line is printing the wrong statement.

18th Feb 2018, 5:48 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
6 Answers
+ 14
Post your code here:-(
18th Feb 2018, 6:29 AM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
+ 12
If possible, please provide a Minimal, Complete, and Verifiable code @ Code Playground so we can help you to take a look on the code. 😉
18th Feb 2018, 8:13 AM
Zephyr Koo
Zephyr Koo - avatar
+ 6
The Alchemist, try this, tested in Code Playground: public class Program { public static void main(String[] args) { String s = "12345"; int x, l = s.length(); System.out.println(s); for(x = 0; x < l; x++) { if(x != 3) System.out.println(s.substring(0, 4) + s.substring(x, x + 1)); } } } Hth, cmiiw
18th Feb 2018, 9:45 AM
Ipang
+ 4
sorry ipang but 12344 is not to be printed
18th Feb 2018, 10:44 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
+ 4
@The Alchemist, sorry skipped that one : ) Code updated, please check again : )
18th Feb 2018, 10:56 AM
Ipang
18th Feb 2018, 9:25 AM
Shubh Mehrotra
Shubh Mehrotra - avatar