Results 11 to 19 of 19
-
12th Sep 2011, 05:29 AM #11OPBanned
need help in this output please..
12345
22345
33345
44445
55555
-
12th Sep 2011, 06:15 AM #12You can call me GCode:
/** * Prints the pattern in the post above. * * @author Gaurav * @version 1.0 */ public class pattern { public static void main(String[] args) { for(int i = 1; i <= 5; i++){ for(int j = 1; j <=5; j++){ if(j < i){ System.out.print(i); } else{ System.out.print(j); } } System.out.println(); } } }
.
One suggestion. Please do try doing the programs yourself first.. If you're stuck somewhere then only look out for help. Just typing in the pattern and asking for the solution gives the impression that you want us to do your homework (not saying that this might be the case). But I and many others would appreciate if you post your progress as well along with the question.
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
-
12th Sep 2011, 07:46 AM #13OPBanned
nope I'm self learning bro, and I really make one for this but the problem is I didn't really think putting if-else in a nested for loop..
-
25th Sep 2011, 02:10 AM #14OPBanned
any can help me out ive been trying so hard but failed..
Output:
54321
4321
321
21
1
But using the "while" syntax. not nested for loop. is it possible?
-
25th Sep 2011, 02:19 AM #15You can call me G
Here you go:
Code:/** * Prints the above mentioned pattern * * @author Gaurav <Gaurav@besthostingforums.com> * @version 1.0 */ public class PatternKWWH { public void display() { int n = 5; while(n >= 1){ int k = n; while(k >= 1){ System.out.print(k); k--; } System.out.println(); n--; } } }
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
-
6th Oct 2011, 01:19 PM #16OPBanned
^ Thank you so much gaurav its perfect.. well I have a new problem bro our professor said "Make a nested loop, that will prints out All Even numbers in in 1-50, and when it goes to 51-100 it prints out odd numbers"
basically when its still 1<50 it will prints out 2,4,6,8..50 and when its 51-100 it prints out 51,53,55,57,59..99..
Ive tried this so far..
Code:public class oddeven { public static void main(String[] args){ System.out.println("Even numbers: "); for(int a=1;a<=50;a++){ if(a%2 == 0){ System.out.println(a); } } System.out.println("Odd numbers: "); for(int a=51;a<=100;a++){ if(a%2 == 1){ System.out.println(a); } } } }
-
6th Oct 2011, 01:33 PM #17MemberWebsite's:
PasteBot.appspot.com^^
Make 1 loop, go from 0 to 100.
In there put an if clause.
So,
Code:if a<50: if a%2 == 0: print a else: if a%2 == 1: print a
It can't get easier than this, and you're struggling to complete them.
So do some reading and get your head around this stuff. Start from the basics. Read your textbook and make sure you understand each word. Use a dictionary if English is not your First Language.
-
9th Oct 2011, 10:19 AM #18MemberWebsite's:
WarezNeed.comSystem.out.println("Odd numbers: "); for(int a=51;a<=100;a++){ if(a%2 == 1){ System.out.println(a);
You Getting Wrong Here Make it 0 instead of 1
Get Your Personal / Corporate Website Starting @ Just Rs. 700/- Per Year
Freelance Web Solution Plz PM Me --
-
10th Oct 2011, 09:41 AM #19You can call me G
He wants to print odd numbers.. so the remainder after dividing by 2 should be one.. He's correct there..
Try this:
Code:/** * Prints the above mentioned pattern * * @author Gaurav <Gaurav@besthostingforums.com> * @version 1.0 */ public class oddeven { public static void main(String[] args){ for(int i = 1; i <= 100; i++) { if(i <= 50 && i % 2 == 0) { System.out.println(i); } else if(i > 50 && i % 2 == 1){ System.out.println(i); } } } }
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java stinks: Turn off your Java browser plugin
By Loget in forum General DiscussionReplies: 37Last Post: 5th Sep 2012, 07:40 AM -
[PHP] Need help to loop true the results
By AndroidApps in forum Web Development AreaReplies: 6Last Post: 5th Feb 2012, 09:56 AM -
Php Loop Prob
By Chris2k in forum Web Development AreaReplies: 1Last Post: 16th Jan 2012, 02:00 PM -
What's the biggest forum out there? Been out of the loop..
By wildfire95 in forum Webmasters, Money MakingReplies: 3Last Post: 7th May 2011, 11:28 AM -
Redirect loop?!?!
By GeeZus in forum Technical Help Desk SupportReplies: 4Last Post: 9th Jun 2009, 04:36 AM
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...