Take String from user count no. Of special characters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Take String from user count no. Of special characters

import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in); System.out.println(" enter any string"); String s=sc.nextLine(); int c=0; char ch; for(int i=0;i<s.lengh();i++) { ch=s.charAt(i); if ((ch>='A'&&ch<='Z')||(ch>='a'&&ch<=z) ||(ch>=0&&ch<=9)||(ch==' ')) { c++; } c=s.length()-c; } System.out.println( "special= "+c);

27th Sep 2022, 8:11 AM
Tanay Rastogi
Tanay Rastogi - avatar
2 Answers
+ 4
Please attach a code bit link instead of raw text code like that, it gets truncated from character limits. https://www.sololearn.com/post/75089/?ref=app And then edit the post Description to include your question ...
27th Sep 2022, 8:49 AM
Ipang
+ 2
Calculate c=s.length()-c; after loop, not inside. ex: sharing code link will help to identify, is code is cut off or you missing to include closing braces..
27th Sep 2022, 10:00 AM
Jayakrishna 🇮🇳