Posts

Showing posts from July, 2021

Reverse each word in sentence without changing position of word (Program_7 by School)

  package School ; import java.util.Scanner ; import java.util.StringTokenizer ; public class Program_7 { public static void main ( String [] args ) { Scanner in = new Scanner ( System . in ); System . out . println ( "Enter Sentence" ); String sentence = in . nextLine (); sentence = sentence . toUpperCase (); String store = "" ; if ( sentence . endsWith ( "." ) || sentence . endsWith ( "!" ) || sentence . endsWith ( "?" )){ sentence = sentence . substring ( 0 , sentence . length () - 1 ); StringTokenizer st = new StringTokenizer ( sentence ); while ( st . hasMoreTokens ()){ store = st . nextToken (); for ( int i = store . length () - 1 ; i >= 0 ; i -- ){ System . out . print ( store . charAt ( i )); } System . out . print ( " " ); } ...

Display and count word which starting and ending with vowel (Problem_6) School

 package School; import java.util.*; class Program_6 {     public static void main(String args[]) {         Scanner in = new Scanner(System.in);         System.out.println("Enter Sentence");         String sentence = in.nextLine();         sentence = sentence.toUpperCase();         String check[] = new String[5];         check[0] = "A";         check[1] = "E";         check[2] = "I";         check[3] = "O";         check[4] = "U";         String Temp = "";         int c = 0;         if (sentence.endsWith(".") || sentence.endsWith("!") || sentence.endsWith("?")) {             sentence = sentence.substring(0, sentence.length() - 1);             StringTokenizer...

Display each word with no of letter in it (Program 4) by School

  import java.util. * ; public class Program_4 { public static void main ( String [] args ) { Scanner in = new Scanner ( System . in ); System . out . println ( "Enter Sentence which end with ? . !" ); String sentence = in . nextLine (); if ( sentence . endsWith ( "." ) || sentence . endsWith ( "!" ) || sentence . endsWith ( "?" )) { sentence = sentence . substring ( 0 , sentence . length () - 1 ); StringTokenizer st = new StringTokenizer ( sentence ); int length = 0 ; String word = "" ; while ( st . hasMoreTokens ()) { word = st . nextToken (); length = word . length (); System . out . println ( word + "\t" + length ); } } else { System . out . println ( "Invalid Input" ); } } }