❖ Replace a given word from a string.
Example : -
Input : I want to eat a pizza.
Replace pizza with cake,
Output : I want to eat a cake.
❖ Write a program to display the number of even and odd
digits in a number input by the user.
Example : -
Input : 7391405
Output : Odd numbers - 5
Even numbers - 2
❖ A program to accept a string and display the number of
uppercase characters, number of lower case characters,
number of special characters and number of digits.
Example : -
Input : %&hV4
Output :
No of Uppercase Characters : 1
No of Lowercsse Characters : 1
No of Numeric Characters : 1
No of Other Characters : 2
❖ Program to display reverse of a number, their difference and
smallest digit in it.
Example : -
Input : 87654321
Output :
Reverse Number : 12345678
Absolute Difference : 75308643
Smallest number : 1
, Program 1 : Replace a given word from a string
Logic :
1. Accept input.
2. Accept the word to be replaced.
3. Use the replace function.
import java.util.Scanner;
public class ReplaceSequence
{
public static void main (String args [])
{
System.out.println("Enter a string.");
Scanner scnr = new Scanner (System.in);
String a = scnr.nextLine();
System.out.println("Enter sequence to be replaced.");
String o = scnr.nextLine();
System.out.println("Enter new sequence.");
String n = scnr.next();
System.out.println("New String : " +a.replace(o,n));
}
}