2021年3月7日星期日

Trying to write a method that is called and returns a string of asterisks in the same number of characters WITH boundaries

New to coding.. So far I have this:

public class Main {      public static void main(String[] args) {            String sOS1 = stringOfStars("a");              System.out.println(sOS1);          String sOS2 = stringOfStars("Hello, world!");              System.out.println(sOS2);          String sOS3 = stringOfStars("012345");              System.out.println(sOS3);  }      static String stringOfStars(String a) {          String string = "";          for(int i = 0; i < a.length(); i++)              string = string + "*";          return string;                    // NEED ADDITIONAL CODE HERE        }  }  

Additional conditions I need:

  1. Return a string of 3 asterisks if the character length is LESS than 3.
  2. Return a string of 10 asterisks if the character length is GREATER than 10.
https://stackoverflow.com/questions/66523612/trying-to-write-a-method-that-is-called-and-returns-a-string-of-asterisks-in-the March 08, 2021 at 10:28AM

没有评论:

发表评论