Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 6 of 6 FirstFirst ... 456
Results 126 to 132 of 132

Thread: 500 Ways to Print 1 to 10

  1. #126
    Junior Member Bethany Ferrell's Avatar
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 500 Ways to Print 1 to 10

    How to count to ten in Yan Tan Tethera

    Java this time, counting to ten in the Derbyshire variant of the old sheep-counting language based on ancient vigesimal, or base-20, Celtic number names. If you've read Terry Pratchett's stories about the adventures of young witch Tiffany Aching and the Nac Mac Feegle (the roughest, most criminally inclined fairies of all time), you'll recognize these as the ones used by shepherds on the Chalk in Discworld. Tiffany, being her twentieth grandchild, is called "little jiggit" by her sheep-herding grandmother.

    Since these number names include pairs of rhyming words, it seemed a good choice for a non-obvious (silly, even) implementation. Five and ten are unique words, so the "prefixes" array contains their translations in full. All other numbers from one to ten are composed of an initial letter followed by one of just three suffixes (or blank for five and ten). To get a full name, combine a prefix with matching suffix. To avoid duplicating suffixes, we iterate through an array of indices into the suffixes array, rather than the suffixes array itself.

    public class YanTanTethera {
      public static void main(String[] args) {
        String[] prefixes = {"y", "t", "t", "m", "pip", "s", "l", "h", "d", "dick"};
        String[] suffixes = {"an", "ethera", "overa", ""};
        int[] suffix_for_num = {0, 0, 1, 1, 3, 1, 1, 2, 2, 3};
        for (int i = 1; i<=10; i++) {
          System.out.println(prefixes[i-1]+suffixes[suffix_for_num[i-1]]);
        }
      }
    }

    Output:
    yan
    tan
    tethera
    methera
    pip
    sethera
    lethera
    hovera
    dovera
    dick


    This is just one dialect of yan tan tethera. There are many more, some quite similar, others more varied. Anyone sufficiently intrigued can try adapting the above to other dialects. Much more information can be found at:

    Yan tan tethera - Wikipedia, the free encyclopedia

  2. #127
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 500 Ways to Print 1 to 10

    [java]Hello[/java]

    --- Update ---

    Hope I didn't copy anyone. Hah!


      class kevi{
     
    	public static void main(String args[]){
     
    		int onetoten;
     
    		for(onetoten=0;onetoten<=100;onetoten+=10){
     
    			System.out.print("\t" +onetoten/10);
     
    		}
     
    	}
     
     
    }


    Output:

    0 1 2 3 4 5 6 7 8 9 10

  3. #128
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 500 Ways to Print 1 to 10

    Hope this one counts..

    public static void main(String[] args) {
    int number = 0;
    recursion(number);
    }
     
    public static void recursion(int number) {
    if (number <= 10) {
    System.out.println(number);
    number++;
    recursion(number);
    }
    }

  4. #129
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 500 Ways to Print 1 to 10

    Quote Originally Posted by helloworld922 View Post
    don't know if this counts.

    6. Java
    public class OneToTen
    {
    public static void main(String[] args)
    {
         System.out.println("1 2 3 4 5 6 7 8 9 10");
    }
    }
    The ultimate neat solution ever, IMHO.

  5. #130
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    My Mood
    Sad
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    System.out.println("1")
    System.out.println("2")
    Etc.

    This easy it is...

    But im going to make a harder one at home.

  6. #131
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    228
    My Mood
    Sleepy
    Thanks
    18
    Thanked 34 Times in 30 Posts

    Default Re: 500 Ways to Print 1 to 10

    Not sure if this method have been attempted:

    package mycounting.pkg;
    public class MainClass
    { 
       public static void main(String[] args)
       {
          Counter count = new Counter(1);
          count.printNumbers();
     
       }
    }
     
    // other .class file -===========-
    package mycounting.pkg;
    import javax.swing.JOptionPane;
     
    public class Counter
    {
       private int number;
     
       public Counter(int defNumber)
       {
          if ((defNumber <= 0) || (defNumber > 1))
             number = defNumber;
     
          number = defNumber;
       }
     
       public void printNumbers()
       {
          int loop = 1;
     
          do
          {
             JOptionPane.showMessageDialog(null, this.number);
             ++loop;
          } while (loop <= 10);
     
       }
    }

    Cryptic way of doing it using the ADA language:

     -- program to add 1 to a declared local variable X
    procedure print_test -- first procedure 
    begin
      Text_IO.Put_Line( "This will print the numbers 1 through 10" );
       int_value : Integer = X;
     
    While_Loop :
       while X <= 10 loop
          Put_Line( & AddOne(X) );     
       end loop While_Loop;
    end print_test; -- terminate first procedure
     
    -- method to add one to the passed parameter argument X
    -- then return it to the calling function X is not a Pointer
    function AddOne( X : integer ) return integer is
    begin
      return X+1;
    end AddOne;

    Forgive me if the syntax isn't 100% - I haven't used the
    ADA language science 1995's revision of it. It's probably
    changed since then too. Anyways - just my two cents.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  7. #132
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    228
    My Mood
    Sleepy
    Thanks
    18
    Thanked 34 Times in 30 Posts

    Default Re: 500 Ways to Print 1 to 10

    Here is why I am glad to not be working with pointers anymore:

    #include <stdio.h>
     
    int main()
    {
       int *ptr = NULL;
       int temp = 1;
       ptr = &temp;
       int x; // C99 
     
       for (x = 1; x <= 10; ++x)
       {
          printf("%d ", *ptr);
          ++(*ptr);
       }
    }

    Sorry I had to make a double post - the "edit" button was craning Fire fox for some reason.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Page 6 of 6 FirstFirst ... 456

Similar Threads

  1. print code to browser
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: April 21st, 2010, 01:09 AM
  2. print space
    By brainTuner in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 1st, 2010, 06:09 PM
  3. How to print results to screen
    By NinjaLink in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2010, 12:46 PM
  4. Can someone please tell me why my code doesn't print out anything?
    By deeerek in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 6th, 2010, 07:35 AM
  5. print hex decimal value
    By ran830421 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 25th, 2009, 06:23 PM