Javatpoint Logo
Javatpoint Logo

Java Program to count the total number of punctuation characters exists in a String

Java Program to count the total number of punctuation characters exists in a String

In this pattern program, we are going to draw above pattern on the output screen with the help of various loops.

Algorithm:

  • STEP 1: START
  • STEP 2: SET lines= 10
  • STEP 3: SET space= (lines*2)-2
  • STEP 4: SET i=1 REPEAT STEP 5 to STEP 18 UNTIL i <= (lines/2)
  • STEP 5: SET flagl=0.
  • STEP 6: SET l=1. REPEAT STEP 7 and 8 UNTIL l <= i.
  • STEP 7: IF flagl is not true PRINT '*' and INCREMENT flagl by 1
                      ELSE PRINT "" WITH "*"
  • STEP 8: SET l=l+1
  • STEP 9: SET l=1
  • STEP 10: REPEAT STEP 11 UNTIL l <= space
  • STEP 11: PRINT "" and SET l=l+1
  • STEP 12: DECREMENT space by 4.
  • STEP 13: SET flagr=0
  • STEP 14: SET l=1. REPEAT STEP 15 to STEP 16 UNTIL l <= i
  • STEP 15: IF flag is not true PRINT * and increment flag by 1.
                      ELSE PRINT BLANK SPACE " " WITH * .
  • STEP 16: SET l=l+1
  • STEP 17: PRINT new line.
  • STEP 18: SET i=i+1.
  • STEP 19: INCREMENT space by 4
  • STEP 20: SET i=lines/2
  • STEP 21: REPEAT STEP 22 to STEP 35 UNTIL i >=1
  • STEP 22: SET flagl=0
  • STEP 23: SET l=1. REPEAT STEP 24 and 25 UNTIL l <= i
  • STEP 24: IF flag is not true PRINT * and INCREMENT flag by 1 ELSE PRINT "" + *
  • STEP 25: SET l=l+1
  • STEP 26: SET l=1. REPEAT STEP 27 and 28 UNTIL l <= space
  • STEP 27: PRINT ""
  • STEP 28: SET l = l + 1
  • STEP 29: INCREMENT space by 4.
  • STEP 30: SET flagr =0.
  • STEP 31: SET l=1. REPEAT STEP 32 to STEP 33 UNTIL l<=i.
  • STEP 32: IF flagr is not true then PRINT * and INCREMENT flagr by 1
                      else
                      PRINT "" with *
  • STEP 33: SET l=l+1
  • STEP 34: PRINT new line.
  • STEP 35: SET i= i-1.
  • STEP 36: END

Program:

Output:

Java Program to count the total number of punctuation characters exists in a String
Next TopicJava Programs




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA