10th Aug 2018, 10:37 AM
Harsh Agrawal
Harsh Agrawal - avatar
22 Respuestas
+ 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
10th Aug 2018, 1:50 PM
‎ ‏‏‎Anonymous Guy
+ 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(); } }
10th Aug 2018, 11:05 AM
MarJan
MarJan - avatar
+ 1
Harsh Agrawal, what do you mean? You can't make it with two nested loops as in your example
10th Aug 2018, 11:08 AM
MarJan
MarJan - avatar
+ 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
10th Aug 2018, 11:16 AM
MarJan
MarJan - avatar
+ 1
Harsh Agrawal i need some more examples for this pattern, for different input
10th Aug 2018, 1:31 PM
‎ ‏‏‎Anonymous Guy
+ 1
harsh do you want a general code for that pattern ?
10th Aug 2018, 1:42 PM
‎ ‏‏‎Anonymous Guy
+ 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
10th Aug 2018, 4:10 PM
‎ ‏‏‎Anonymous Guy
+ 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(""); } } } }
10th Aug 2018, 4:45 PM
[A^dr3w]
[A^dr3w] - avatar
+ 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++; } } }
10th Aug 2018, 5:09 PM
[A^dr3w]
[A^dr3w] - avatar
+ 1
thnxzzz All of u
11th Aug 2018, 4:38 AM
Harsh Agrawal
Harsh Agrawal - avatar
0
MarJan can u make it simple??????
10th Aug 2018, 11:07 AM
Harsh Agrawal
Harsh Agrawal - avatar
0
MarJan i mean can we cant make this without calling it four time?????
10th Aug 2018, 11:13 AM
Harsh Agrawal
Harsh Agrawal - avatar
0
okkk thnxzzz MarJan
10th Aug 2018, 11:17 AM
Harsh Agrawal
Harsh Agrawal - avatar
0
‎ ‏‏‎Sreejith  what is dat????? can u give me???
10th Aug 2018, 1:40 PM
Harsh Agrawal
Harsh Agrawal - avatar
0
‎ ‏‏‎Sreejith  ya i want or u wll also give suggestion about this!!!
10th Aug 2018, 1:44 PM
Harsh Agrawal
Harsh Agrawal - avatar
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????
10th Aug 2018, 3:43 PM
Harsh Agrawal
Harsh Agrawal - avatar
0
ohh!!!
11th Aug 2018, 1:52 PM
Raj gupta
Raj gupta - avatar
0
harsh agarwal can you solve this pattern in simple way so plzz this pattern program make and make a public
11th Aug 2018, 1:53 PM
Raj gupta
Raj gupta - avatar
0
Raj gupta what do u mean????? can u elaborate what u want????
11th Aug 2018, 1:57 PM
Harsh Agrawal
Harsh Agrawal - avatar
0
i means make a code for this program and makes privacy public
11th Aug 2018, 2:27 PM
Raj gupta
Raj gupta - avatar