Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2007, 06:46 PM
Member
 
Join Date: Dec 2007
Posts: 2
radio is on a distinguished road
Counting numbers up and down
Hi my name is John,

basically i try to write a program that can print this
2
3
4
5
4
3
2
1

but the i can print from 1 to 5 and i dont know how to go from 4,3,2,1 etc...

Code:
/** * Write a description of class Counting here. * @author (your name) * @version (a version number or a date) */ public class Counting { // instance variables - replace the example below with your own public int z = 5; /** * Constructor for objects of class Counting */ public Counting() { for (int x = 5; x >=1; x--) { for (int y = 1; y<=5; y++) { System.out.println(y); } System.out.println(x); } } public static void main(String [] args) { Counting ncounting = new Counting(); } }
i am very new to java, a help would be greatful.

thanks in advance

John
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-01-2007, 07:17 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
reverse the for loop
Code:
for (int i = 5; i >= 0; i--) { System.out.println(i); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 07:49 PM
Member
 
Join Date: Dec 2007
Posts: 2
radio is on a distinguished road
hi there,

thanks for the reply but i've tried your method it didnt worked also

can you rather than giving the hint, please re-correct my code, as i am new to java, i dont understand the clue's or hint's..3

thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-01-2007, 08:08 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Being new to java doesnt mean that you cant spend a little time thinking, or actually attempt to solve the problem:

Code:
public class Counting { // instance variables - replace the example below with your own public int z = 5; /** * Constructor for objects of class Counting */ public Counting() { for (int y = 1; y <= 5; y++) { System.out.println(y); } for (int x = 5; x >= 1; x--) { System.out.println(x); } } public static void main(String[] args) { Counting ncounting = new Counting(); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare 5 numbers Snowboardmylife New To Java 5 04-15-2008 08:04 PM
Prime numbers gapper New To Java 3 02-07-2008 11:09 AM
random numbers carlos123 New To Java 1 12-22-2007 03:56 AM
Counting Pixels shaungoater Java 2D 5 11-29-2007 06:51 PM
Counting Vowels and Constonants MattN New To Java 3 11-20-2007 06:45 PM


All times are GMT +3. The time now is 02:39 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org