27-10-2014, 19:33
Siem
Od 2h staram sie rozwiazac jedno zadanie i juz mi sie mozg zaczyna gotowac...
Pytanie:
Stworz metode makeRow oraz printTriangle ktora przekaze int n i String s ,a nastepnie wydrukuje trojkat.
Na przyklad printTriangle(13, "*"); wydrukuje
Niby nic trudnego, ale juz nie mam pomyslow :/
Najblizej bylem z tym kodem
Od 2h staram sie rozwiazac jedno zadanie i juz mi sie mozg zaczyna gotowac...
Pytanie:
Stworz metode makeRow oraz printTriangle ktora przekaze int n i String s ,a nastepnie wydrukuje trojkat.
Na przyklad printTriangle(13, "*"); wydrukuje
Kod:
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
Najblizej bylem z tym kodem
Kod:
public class Exercise10 {
public static void main(String[] args) {
makeTriangle3(13,"*", " ");
}
public static void row(int n, String s, String b)
{
for(int j=n; j>=0; j--)
{
System.out.print(b);
}
for(int i=1; i <= n; i++)
{
System.out.print(s);
}
}
public static void makeTriangle3(int n, String s, String b)
{
for(int i=1; i <=n; i++)
{
row(i,s,b);
System.out.println();
}
}
}