How to make this kind of custom algorithm in Java? [closed]












0















I am enhancing my Java skills for my own personal purpose,



And I am wondering, how to make this algorithm in Java :



* 2 3 4 5
* * 3 4 5
* * * 4 5
* * * * 5
* * * * *
* * * * *
* * * * 5
* * * 4 5
* * 3 4 5
* 2 3 4 5




So far from now I managed to do this :



*
**
***
****
*****

for (int i = 1; i <=5 ; i++) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
System.out.println(" ");
}




And I wanted to do something harder.










share|improve this question















closed as too broad by Stephen C, meowgoesthedog, cнŝdk, Dukeling, JJJ Nov 20 '18 at 14:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 10





    Solution: keep working at it. That's the best way to learn how to program. Practice.

    – Stephen C
    Nov 20 '18 at 11:50













  • Hint: one way to do this is to change the inner loop to always run to 5, and use an if inside. Another option is to use a second, separate inner loop for the numbers.

    – Hulk
    Nov 20 '18 at 11:55











  • I prefer the second inner loop, @Hulk. It will be easier to read even when calculating the loop start and end points is not quite so trivial.

    – Ole V.V.
    Nov 20 '18 at 12:03











  • You can use recursion to build the lower half. When the call returns back, print the same line again and it's done.

    – vivek_23
    Nov 20 '18 at 12:07













  • Ok thanks, I'm still working on it.

    – Finalmix6
    Nov 20 '18 at 12:12
















0















I am enhancing my Java skills for my own personal purpose,



And I am wondering, how to make this algorithm in Java :



* 2 3 4 5
* * 3 4 5
* * * 4 5
* * * * 5
* * * * *
* * * * *
* * * * 5
* * * 4 5
* * 3 4 5
* 2 3 4 5




So far from now I managed to do this :



*
**
***
****
*****

for (int i = 1; i <=5 ; i++) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
System.out.println(" ");
}




And I wanted to do something harder.










share|improve this question















closed as too broad by Stephen C, meowgoesthedog, cнŝdk, Dukeling, JJJ Nov 20 '18 at 14:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 10





    Solution: keep working at it. That's the best way to learn how to program. Practice.

    – Stephen C
    Nov 20 '18 at 11:50













  • Hint: one way to do this is to change the inner loop to always run to 5, and use an if inside. Another option is to use a second, separate inner loop for the numbers.

    – Hulk
    Nov 20 '18 at 11:55











  • I prefer the second inner loop, @Hulk. It will be easier to read even when calculating the loop start and end points is not quite so trivial.

    – Ole V.V.
    Nov 20 '18 at 12:03











  • You can use recursion to build the lower half. When the call returns back, print the same line again and it's done.

    – vivek_23
    Nov 20 '18 at 12:07













  • Ok thanks, I'm still working on it.

    – Finalmix6
    Nov 20 '18 at 12:12














0












0








0








I am enhancing my Java skills for my own personal purpose,



And I am wondering, how to make this algorithm in Java :



* 2 3 4 5
* * 3 4 5
* * * 4 5
* * * * 5
* * * * *
* * * * *
* * * * 5
* * * 4 5
* * 3 4 5
* 2 3 4 5




So far from now I managed to do this :



*
**
***
****
*****

for (int i = 1; i <=5 ; i++) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
System.out.println(" ");
}




And I wanted to do something harder.










share|improve this question
















I am enhancing my Java skills for my own personal purpose,



And I am wondering, how to make this algorithm in Java :



* 2 3 4 5
* * 3 4 5
* * * 4 5
* * * * 5
* * * * *
* * * * *
* * * * 5
* * * 4 5
* * 3 4 5
* 2 3 4 5




So far from now I managed to do this :



*
**
***
****
*****

for (int i = 1; i <=5 ; i++) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
System.out.println(" ");
}




And I wanted to do something harder.







java algorithm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 12:22









meowgoesthedog

9,99241527




9,99241527










asked Nov 20 '18 at 11:48









Finalmix6Finalmix6

887




887




closed as too broad by Stephen C, meowgoesthedog, cнŝdk, Dukeling, JJJ Nov 20 '18 at 14:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by Stephen C, meowgoesthedog, cнŝdk, Dukeling, JJJ Nov 20 '18 at 14:02


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 10





    Solution: keep working at it. That's the best way to learn how to program. Practice.

    – Stephen C
    Nov 20 '18 at 11:50













  • Hint: one way to do this is to change the inner loop to always run to 5, and use an if inside. Another option is to use a second, separate inner loop for the numbers.

    – Hulk
    Nov 20 '18 at 11:55











  • I prefer the second inner loop, @Hulk. It will be easier to read even when calculating the loop start and end points is not quite so trivial.

    – Ole V.V.
    Nov 20 '18 at 12:03











  • You can use recursion to build the lower half. When the call returns back, print the same line again and it's done.

    – vivek_23
    Nov 20 '18 at 12:07













  • Ok thanks, I'm still working on it.

    – Finalmix6
    Nov 20 '18 at 12:12














  • 10





    Solution: keep working at it. That's the best way to learn how to program. Practice.

    – Stephen C
    Nov 20 '18 at 11:50













  • Hint: one way to do this is to change the inner loop to always run to 5, and use an if inside. Another option is to use a second, separate inner loop for the numbers.

    – Hulk
    Nov 20 '18 at 11:55











  • I prefer the second inner loop, @Hulk. It will be easier to read even when calculating the loop start and end points is not quite so trivial.

    – Ole V.V.
    Nov 20 '18 at 12:03











  • You can use recursion to build the lower half. When the call returns back, print the same line again and it's done.

    – vivek_23
    Nov 20 '18 at 12:07













  • Ok thanks, I'm still working on it.

    – Finalmix6
    Nov 20 '18 at 12:12








10




10





Solution: keep working at it. That's the best way to learn how to program. Practice.

– Stephen C
Nov 20 '18 at 11:50







Solution: keep working at it. That's the best way to learn how to program. Practice.

– Stephen C
Nov 20 '18 at 11:50















Hint: one way to do this is to change the inner loop to always run to 5, and use an if inside. Another option is to use a second, separate inner loop for the numbers.

– Hulk
Nov 20 '18 at 11:55





Hint: one way to do this is to change the inner loop to always run to 5, and use an if inside. Another option is to use a second, separate inner loop for the numbers.

– Hulk
Nov 20 '18 at 11:55













I prefer the second inner loop, @Hulk. It will be easier to read even when calculating the loop start and end points is not quite so trivial.

– Ole V.V.
Nov 20 '18 at 12:03





I prefer the second inner loop, @Hulk. It will be easier to read even when calculating the loop start and end points is not quite so trivial.

– Ole V.V.
Nov 20 '18 at 12:03













You can use recursion to build the lower half. When the call returns back, print the same line again and it's done.

– vivek_23
Nov 20 '18 at 12:07







You can use recursion to build the lower half. When the call returns back, print the same line again and it's done.

– vivek_23
Nov 20 '18 at 12:07















Ok thanks, I'm still working on it.

– Finalmix6
Nov 20 '18 at 12:12





Ok thanks, I'm still working on it.

– Finalmix6
Nov 20 '18 at 12:12












3 Answers
3






active

oldest

votes


















1














This should be of some help:



public static void printTree()
{
int index = 0;
for(; index < 5; index++)
{
for(int j = 0; j < 5; j++)
{
if(j <= index)
{
System.out.print("*");
}
else
{
System.out.print(j + 1);
}
}
System.out.println();
}
for(; index > 0; index--)
{
for(int j = 0; j < 5; j++)
{
if(j < index)
{
System.out.print("*");
}
else
{
System.out.print(j + 1);
}
}
System.out.println();
}
}





share|improve this answer



















  • 1





    Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

    – Finalmix6
    Nov 20 '18 at 12:28



















2














The way to program is to break the problem up into smaller chunks and work on one chunk at a time. Always test each chunk before moving on to the next.




  1. Make rows of stars getting longer. You have done this.


  2. Make rows of stars getting shorter.


  3. Make rows of digits, increasing.


  4. Make rows of digits, decreasing.


  5. Append the decreasing digits to the increasing stars.


  6. Append the increasing digits to the decreasing stars.


  7. Put 5 and 6 together.







share|improve this answer
























  • Thank you for these tips, I'm working on it.

    – Finalmix6
    Nov 20 '18 at 12:12



















1














    for (int i = 1; i <=5 ; i++) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
for (int k = i+1; k <= 5 ; k++) {
System.out.print(k);
}

System.out.println(" ");
}


for (int i = 5; i > 0 ; i--) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
for (int k = i+1; k <= 5 ; k++) {
System.out.print(k);
}

System.out.println(" ");
}




I don't know if it is the best way, but it seems to work.
I will try another way. Always good to learn.






share|improve this answer
































    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This should be of some help:



    public static void printTree()
    {
    int index = 0;
    for(; index < 5; index++)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j <= index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    for(; index > 0; index--)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j < index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    }





    share|improve this answer



















    • 1





      Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

      – Finalmix6
      Nov 20 '18 at 12:28
















    1














    This should be of some help:



    public static void printTree()
    {
    int index = 0;
    for(; index < 5; index++)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j <= index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    for(; index > 0; index--)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j < index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    }





    share|improve this answer



















    • 1





      Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

      – Finalmix6
      Nov 20 '18 at 12:28














    1












    1








    1







    This should be of some help:



    public static void printTree()
    {
    int index = 0;
    for(; index < 5; index++)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j <= index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    for(; index > 0; index--)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j < index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    }





    share|improve this answer













    This should be of some help:



    public static void printTree()
    {
    int index = 0;
    for(; index < 5; index++)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j <= index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    for(; index > 0; index--)
    {
    for(int j = 0; j < 5; j++)
    {
    if(j < index)
    {
    System.out.print("*");
    }
    else
    {
    System.out.print(j + 1);
    }
    }
    System.out.println();
    }
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 '18 at 12:25









    Karan KhannaKaran Khanna

    633628




    633628








    • 1





      Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

      – Finalmix6
      Nov 20 '18 at 12:28














    • 1





      Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

      – Finalmix6
      Nov 20 '18 at 12:28








    1




    1





    Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

    – Finalmix6
    Nov 20 '18 at 12:28





    Oh your solution is even better than mine ! Thank you, I will learn if there is some others ways to do it.

    – Finalmix6
    Nov 20 '18 at 12:28













    2














    The way to program is to break the problem up into smaller chunks and work on one chunk at a time. Always test each chunk before moving on to the next.




    1. Make rows of stars getting longer. You have done this.


    2. Make rows of stars getting shorter.


    3. Make rows of digits, increasing.


    4. Make rows of digits, decreasing.


    5. Append the decreasing digits to the increasing stars.


    6. Append the increasing digits to the decreasing stars.


    7. Put 5 and 6 together.







    share|improve this answer
























    • Thank you for these tips, I'm working on it.

      – Finalmix6
      Nov 20 '18 at 12:12
















    2














    The way to program is to break the problem up into smaller chunks and work on one chunk at a time. Always test each chunk before moving on to the next.




    1. Make rows of stars getting longer. You have done this.


    2. Make rows of stars getting shorter.


    3. Make rows of digits, increasing.


    4. Make rows of digits, decreasing.


    5. Append the decreasing digits to the increasing stars.


    6. Append the increasing digits to the decreasing stars.


    7. Put 5 and 6 together.







    share|improve this answer
























    • Thank you for these tips, I'm working on it.

      – Finalmix6
      Nov 20 '18 at 12:12














    2












    2








    2







    The way to program is to break the problem up into smaller chunks and work on one chunk at a time. Always test each chunk before moving on to the next.




    1. Make rows of stars getting longer. You have done this.


    2. Make rows of stars getting shorter.


    3. Make rows of digits, increasing.


    4. Make rows of digits, decreasing.


    5. Append the decreasing digits to the increasing stars.


    6. Append the increasing digits to the decreasing stars.


    7. Put 5 and 6 together.







    share|improve this answer













    The way to program is to break the problem up into smaller chunks and work on one chunk at a time. Always test each chunk before moving on to the next.




    1. Make rows of stars getting longer. You have done this.


    2. Make rows of stars getting shorter.


    3. Make rows of digits, increasing.


    4. Make rows of digits, decreasing.


    5. Append the decreasing digits to the increasing stars.


    6. Append the increasing digits to the decreasing stars.


    7. Put 5 and 6 together.








    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 '18 at 12:01









    rossumrossum

    12.6k11431




    12.6k11431













    • Thank you for these tips, I'm working on it.

      – Finalmix6
      Nov 20 '18 at 12:12



















    • Thank you for these tips, I'm working on it.

      – Finalmix6
      Nov 20 '18 at 12:12

















    Thank you for these tips, I'm working on it.

    – Finalmix6
    Nov 20 '18 at 12:12





    Thank you for these tips, I'm working on it.

    – Finalmix6
    Nov 20 '18 at 12:12











    1














        for (int i = 1; i <=5 ; i++) {
    for (int j = 1; j <=i ; j++) {
    System.out.print("*");
    }
    for (int k = i+1; k <= 5 ; k++) {
    System.out.print(k);
    }

    System.out.println(" ");
    }


    for (int i = 5; i > 0 ; i--) {
    for (int j = 1; j <=i ; j++) {
    System.out.print("*");
    }
    for (int k = i+1; k <= 5 ; k++) {
    System.out.print(k);
    }

    System.out.println(" ");
    }




    I don't know if it is the best way, but it seems to work.
    I will try another way. Always good to learn.






    share|improve this answer






























      1














          for (int i = 1; i <=5 ; i++) {
      for (int j = 1; j <=i ; j++) {
      System.out.print("*");
      }
      for (int k = i+1; k <= 5 ; k++) {
      System.out.print(k);
      }

      System.out.println(" ");
      }


      for (int i = 5; i > 0 ; i--) {
      for (int j = 1; j <=i ; j++) {
      System.out.print("*");
      }
      for (int k = i+1; k <= 5 ; k++) {
      System.out.print(k);
      }

      System.out.println(" ");
      }




      I don't know if it is the best way, but it seems to work.
      I will try another way. Always good to learn.






      share|improve this answer




























        1












        1








        1







            for (int i = 1; i <=5 ; i++) {
        for (int j = 1; j <=i ; j++) {
        System.out.print("*");
        }
        for (int k = i+1; k <= 5 ; k++) {
        System.out.print(k);
        }

        System.out.println(" ");
        }


        for (int i = 5; i > 0 ; i--) {
        for (int j = 1; j <=i ; j++) {
        System.out.print("*");
        }
        for (int k = i+1; k <= 5 ; k++) {
        System.out.print(k);
        }

        System.out.println(" ");
        }




        I don't know if it is the best way, but it seems to work.
        I will try another way. Always good to learn.






        share|improve this answer















            for (int i = 1; i <=5 ; i++) {
        for (int j = 1; j <=i ; j++) {
        System.out.print("*");
        }
        for (int k = i+1; k <= 5 ; k++) {
        System.out.print(k);
        }

        System.out.println(" ");
        }


        for (int i = 5; i > 0 ; i--) {
        for (int j = 1; j <=i ; j++) {
        System.out.print("*");
        }
        for (int k = i+1; k <= 5 ; k++) {
        System.out.print(k);
        }

        System.out.println(" ");
        }




        I don't know if it is the best way, but it seems to work.
        I will try another way. Always good to learn.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 12:29

























        answered Nov 20 '18 at 12:22









        Finalmix6Finalmix6

        887




        887















            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?