* STRING PROGRAMS* HOW TO CHECK NUMBER OF SPACES AND WORDS IN A STRING USING JAVA PROGRAM. logic: Example: I am an ICSE student The above sentence has 5 words and 4(5-1) spaces.So to find the number of words we have to find the number of spaces and add (+1) to it. import java .io.*; class words_spaces { public static void main(String args[])throws IOException { int l,i,count=0; String b ; // declaring variables to be used in the program char s,y; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.p...
Posts
- Get link
- X
- Other Apps
Write a program to check whether a number is niven number or not. A number which can be divided by the sum of its digit is called a niven number or a harshad number. The number 18 is a Harshad number in base 10, because the sum of the digits 1 and 8 is 9 (1 + 8 = 9), and 18 is divisible by 9 (since 18 % 9 = 0) import java.util.*; class Niven Number { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print( "Enter a number : " ); int n = sc.nextInt(); int c = n, d, sum = 0 ; //finding sum of digits ...