Q2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your string : "); String myWords = scanner.nextLine(); System.out.print("Total number of characters in a string : "); System.out.println(myWords.replaceAll(" ", "").length()); } }