@BenzR: Please create a new thread in the Java Help section to get more help on this. You're hijacking a thread!
where is the help section

Edited by dargueta, 28 April 2013 - 08:41 PM.
Siten0308 - Jun 20 2019 01:43 PM
johnnylo - Apr 23 2019 07:49 AM
PJohnson - Apr 18 2019 03:55 AM
xarzu - Apr 05 2019 09:17 AM
xarzu - Apr 04 2019 11:47 AM
Posted 10 October 2010 - 04:42 AM
@BenzR: Please create a new thread in the Java Help section to get more help on this. You're hijacking a thread!
Edited by dargueta, 28 April 2013 - 08:41 PM.
Posted 12 October 2010 - 07:37 AM
Posted 12 October 2010 - 08:51 AM
int number = 15; for(int i=0 ; i<5 ; i++){ for(int j=0 ; j<5-i ; j++){ System.out.print(number--); } }
Posted 19 October 2010 - 12:17 AM
i am a rookie from java...i find it is quite hard for me:crying:
i wanna know how to print out like this?
88888881
88888812
88888123
88881234
88812345
88123456
81234567
12345678
could someone tell me the solution?
{ int n = 8; int i; int j; for (i=1;i<=n;i++) { for (j=n;j>i;j--) { System.out.print(n); } for( j=1; j<=i;j++) { System.out.print(j); } System.out.println(); } }
Posted 24 October 2010 - 03:24 AM
Posted 26 October 2010 - 06:39 AM
public class asma { public static void main(String [] args) { for (int i=1; i<=4; i++) { for (int j=4; j>=i; j--) { System.out.print(i); } System.out.println(j); } }
Edited by Alexander, 26 October 2010 - 09:49 AM.
Added [code] tags
Posted 31 October 2010 - 05:09 PM
+---+ / /| +---+ | | | + | |/ +---+
..................+---+ ................./ /| ................+---+ | ................| | + ................| |/| ........+---+...+---+ | ......./ /|...| | + ......+---+ |...| |/| ......| | +...+---+ | ......| |/|-+.| | + ......+---+ |/|.| |/| ......| | +---+---+ | ......| |/ /| | + ..+---+---+---+ | |/| ./ /| | | +---+ | +---+ | | |/ /| + | | +---+---+---+ |/. | |/ / / /| +.. +---+---+---+---+ |/... | | | | | +.... | | | | |/..... +---+---+---+---+......
Posted 28 November 2010 - 05:13 PM
Posted 29 November 2010 - 07:50 AM
88888881 88888812 88888123 88881234 88812345 88123456 81234567 12345678The first things you want to do is count the number of rows: 8
for( int i=0 ; i<[B][SIZE="4"]8[/SIZE][/B] ; i++){ System.out.println(""); }the println() will just make an "enter" / a newline.
8888888 888888 88888 8888 888 88 8AND
1 12 123 1234 12345 123456 1234567 12345678There are 2 things there. We start with the eights:
i #times to be printed 0 7 1 6 2 5 3 4 4 3 5 2 6 1 7 0I hope everyone sees that #times to be printed is 7-i. If you don't see this, I suggest you go get some extra math classes.
for( int i=0 ; i<8 ; i++){ for( int j=0 ; j<7-i ; j++ ) { System.out.print("8"); } System.out.println(""); }Note it's a .print() in there, and no .printLN() we don't want newlines after every 8.
1 12 123 1234 12345 123456 1234567 12345678
i #times to be printed 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8IF you don't see here that #times to be printed = i+1, you really really need to take those math classes.
for(int k=0 ; k<i+1; k++){ System.out.print("?"); }Unlike the previous loop the value that's printed is not constant. We need to figure out what it depends on.
i k #value to be printed 0 0 1 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 1 0 1 1 1 2 ...You could complete the table there but i hope it's allready clear.
for(int k=0 ; k<i+1; k++){ System.out.print([B]k+1[/B]); }
for( int i=0 ; i<8 ; i++){ for( int j=0 ; j<7-i ; j++ ) { System.out.print("8"); } for(int k=0 ; k<i+1; k++){ System.out.print(k+1); } System.out.println(""); } OUTPUT ------ 88888881 88888812 88888123 88881234 88812345 88123456 81234567 12345678
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1Amount of rows:5
for(int i=0 ; i<5 ; i++){ System.out.println(""); }First look at the amount of times a value has to be printed:
i #times to be printed 0 5 1 4 2 3 3 2 4 1--> "#times to be printed = 5-i" if you fail to see this ... you know..
for(int j=0 ; j<5-i ; j++){ System.out.print("?"); }Now the value that needs to be printed
i k #value to be printed 0 0 15 0 1 14 0 2 13 0 3 12 0 4 11 ---next loop--- 1 0 10 1 1 9 1 2 8 1 3 7 ---next loop--- 2 0 6 2 1 5 2 2 4 ---next loop--- 3 0 3 3 1 2 ---next loop--- 4 0 1Here the value that has to be printed has nothing to do with anything. It's just a number 15 that's lowered by 1 every loop.
int number = 15; -----above all loops----- -----inside loop----- for(int j=0 ; j<5-i ; j++){ System.out.print(number + " "); number = number -1; }(don't forget to print the space)
int number=15; for(int i=0 ; i<5 ; i++){ for(int j=0 ; j<5-i ; j++){ System.out.print(number +" "); number = number -1; } System.out.println(""); } OUTPUT ------ 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
1 22 333 4444 55555Amount of rows: 5
for(int i=0 ; i<5 ; i++){ System.out.println(""); }How many times is it printed each row?
0 1 1 2 2 3 3 4 4 5So this is i+1 = condition
for(int j=0 ; j<i+1 ; j++){ System.out.print("?"); }What values are printed each row?
0 1 1 2 2 3 3 4 4 5so this is also i+1
for(int j=0 ; j<i+1 ; j++){ System.out.print(i+1); }Put into outer loop:
for(int i=0 ; i<5 ; i++){ for(int j=0 ; j<i+1 ; j++){ System.out.print(i+1); } System.out.println(""); }TADAAA, done.
Edited by wim DC, 29 November 2010 - 09:01 AM.
Posted 30 November 2010 - 12:54 PM
Posted 01 December 2010 - 10:47 AM
That's very simple because the StringBuilder class has a .reverse() method.I need help on how to write a method that will return the reverse of an inputted word
public String reverse (String word)
{
}
StringBuilder sb = new StringBuilder("MyWord"); String reverse = sb.reverse().toString(); System.out.println(reverse); ---output--- droWyMDidn't really test this code but i suppose it's correct.
Posted 01 December 2010 - 12:26 PM
All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.
Language Forums →
PHP →
Content and title won't show on certain page in WordpressStarted by Mello, 05 Jan 2016 ![]() |
|
![]() |
||
![]() Average does not calculate after For LoopStarted by dreddooo, 22 Apr 2015 ![]() |
|
![]() |
||
Language Forums →
C# →
Create Staircase with Nested LoopsStarted by StainedSilva, 12 Mar 2015 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
Bash / Shell Scripting →
Here is a task... Find Nothing :PStarted by ShaunPrawn, 07 Aug 2014 ![]() |
|
![]() |
||
General Forums →
General Programming →
Trying to do a working loopStarted by Error, 23 Jun 2014 ![]() |
|
![]() |