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
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;
}
}
}
+ 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.
+ 2
Just create an array, loop through it, and print each result through each loop through.
0
absolutely
0
it can be done without doing Array
but I am not getting the "idea"
0
now tell me how to make that one which I have asked you .
- 1
did u tried by yourself?
- 1
show Ur code.. where u have problem
- 1
why did you took Len line a and x?
- 1
why did you add the Scanner class when u haven't used it?