Posts

Showing posts from January, 2023

Practice Program list

1. Print Numbers from 1 to 10 2.Print Even Numbers between 1 and 20: 3.Calculate the Sum of Numbers from 1 to 100: 4.Print Multiplication Table of 5: 5.Reverse a String: 6.Factorial of a Number: 7.Check if a Number is Prime: 8.Fibonacci Series up to 10 terms: 9.Count Digits in a Number 10.

Java Program to Count Number of Words in Given String

 Java Program to Count Number of Words in Given String //Java Program to Count Number of Words in Given String class WordCount { public static void main(String[] args) { String str="hello this is shweta, i am from bihar"; int count=0; for(int i=0;i<str.length();i++){ if(str.charAt(i)==' '){ count++; } } System.out.println(count); System.out.println("So , total number of words are :"+(count+1)); } }