Skip to content

Instantly share code, notes, and snippets.

@Zulqurnain
Last active April 10, 2016 18:56
Show Gist options
  • Save Zulqurnain/1f636316742a7984f0a5 to your computer and use it in GitHub Desktop.
Save Zulqurnain/1f636316742a7984f0a5 to your computer and use it in GitHub Desktop.
Java code to take paragraph as an input from user and do the following: 1.count total number of character 2.count total number of spaces 3.count total number of string (are)
package basics;
import java.util.*;
class Basics{ // by Zulqurnain jutt
public static void main(String argv[]) {
String s;
Scanner sc=new Scanner(System.in);
System.out.print("::Start Entering Paragraph from Here::\n\t"); s=sc.nextLine();
char[] c=s.toCharArray();
System.out.print("\nTotal Character :=:"+c.length+"\nTotal Spaces :=:"+ (s.length()-s.replace(" ", "").toCharArray().length));
System.out.println("\nTotal Strings :=:"+ s.split(" ").length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment