0

How to make this

if I enter 13 the result should this given pattern . can anyone explain me clearly . {I am doing looping in java} 1 2,3 4,5,6 7,8,9,10 11,12,13

5th Jul 2017, 2:31 PM
Irwin Lopez
Irwin Lopez - avatar
10 Answers
+ 1
I know to make one I am showing the sample import java.io.*; import java.util.*; public calss slop { public static void main (String[]st) throws IOException { Scanner sc=new Scanner (System.in); int len,line,a,x; System.out.print ("Enter a number") line=1; x=1; while (line <=len) { while (a <=line) { System.out.print (x) x++; a=a+1; } System. out.println () ++line; } } }
5th Jul 2017, 2:50 PM
Irwin Lopez
Irwin Lopez - avatar
+ 4
You could use a single for loop. Use a temp variable to keep track of whatever itteration you are on. Create another different variable and set it equal to. When teml reaches the different variable, reset the temp variable to the original value and move to the next line. Then increment the different variable. The different variable will then have a value of 2. That process will keep repeating because of the loop. So temp will increase till 2, reset, and the different variable will keep increasing. So the different variable is really just how many numbers will be on a row, and the temp is how many we've already placed. Inside the loop you can print the variable from the for loop. If the different variable is equal to the temp, you do not add a comma at the end of a number.
5th Jul 2017, 3:07 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Just create an array, loop through it, and print each result through each loop through.
5th Jul 2017, 2:39 PM
AgentSmith
0
absolutely
5th Jul 2017, 2:33 PM
Irwin Lopez
Irwin Lopez - avatar
0
it can be done without doing Array but I am not getting the "idea"
5th Jul 2017, 2:40 PM
Irwin Lopez
Irwin Lopez - avatar
0
now tell me how to make that one which I have asked you .
5th Jul 2017, 2:52 PM
Irwin Lopez
Irwin Lopez - avatar
- 1
did u tried by yourself?
5th Jul 2017, 2:32 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
- 1
show Ur code.. where u have problem
5th Jul 2017, 2:47 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
- 1
why did you took Len line a and x?
5th Jul 2017, 2:55 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
- 1
why did you add the Scanner class when u haven't used it?
5th Jul 2017, 2:56 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar