+ 1
How can i get the pattern as like this?????
https://code.sololearn.com/cMrh2IQlsi2D/?ref=app output-- *111* **111 111** *111* Helga Arun Tomar Dan Walker Dev Hans Larry Sreejith HAWKEYE Fata1 Err0r Gaurav Agrawal [A^dr3w]
22 Respostas
+ 3
ok, the problem is this could be a sub-pattern of many patterns.
1. the no. ones and * could be constant
2. no. of 1's increase with varying input
3. no. of * increases with varying input
now i'll be considering no. of 1's as constant.
Harsh Agrawal
here's the code...
Is this what you wanted?
https://code.sololearn.com/cVsY8vtzK5Dz/?ref=app
+ 3
Probably the most automated way:
public class Program
{
public static void main(String[] args) {
printRow(0,4);
printRow(0,1);
printRow(3,4);
printRow(0,4);
}
static void printRow(int x, int y){
for(int j=0;j<5;j++){
if(j==x || j==y)
System.out.print("*");
else
System.out.print("1");
}
System.out.println();
}
}
+ 1
Harsh Agrawal, what do you mean? You can't make it with two nested loops as in your example
+ 1
we can hardcode it in main, but that’s the worst solution. In this case a method for printing a row is the most efficient solution
+ 1
Harsh Agrawal i need some more examples for this pattern, for different input
+ 1
harsh do you want a general code for that pattern ?
+ 1
Harsh Agrawal
first take a single line and divide it into multiple parts,
-> each line has 3 one's and 2 *, only order changes
-> stars on the right decreases whereas the star on left increases, once they reach the limit, pattern restarts
-> 111 is constant throughout the series.
-> input can be no. of lines,
.. no. of 1's = 3 [constant]
.. no. of stars in a line = (input/2)+1 (divided among left and right side)
.. no. of elements in a line = input - 1
+ 1
Hi
public class Program
{
public static void main(String[] args)
{
char arr[]={'*','1','1','1','*','*','*','1','1','1'};
for(int a = 0; a <=9; a++)
{
System.out.print(arr[a]);
if(a == 4 || a == 9)
{
System.out.println("");
}
}
for(int a = 9; a >=0; a--)
{
System.out.print(arr[a]);
if(a == 5)
{
System.out.println("");
}
}
}
}
+ 1
or
public class Program
{
public static void main(String[] args)
{
int count=0;
String arr[]={"*111*","**111","111**"};
for(int a = 0; a <=3; a++)
{
System.out.println(arr[count]);
if (count == 2) count = 0;
count++;
}
}
}
+ 1
thnxzzz All of u
0
MarJan
can u make it simple??????
0
MarJan i mean can we cant make this without calling it four time?????
0
okkk thnxzzz MarJan
0
Sreejith what is dat?????
can u give me???
0
Sreejith ya i want or u wll also give suggestion about this!!!
0
Sreejith thnxzzzz but one thing i want to know that how u solve the pattern???? Is der any sequence to solve pattern easily n quickly????
0
ohh!!!
0
harsh agarwal can you solve this pattern in simple way so plzz this pattern program make and make a public
0
Raj gupta what do u mean?????
can u elaborate what u want????
0
i means make a code for this program and makes privacy public