You are given the statement String s1 inputnextLinewhere in
Solution
1)
import java.util.Scanner;
 public class ScannerDemo {
   public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println(\"enter the string\");
        String s1=scanner.nextLine();
        //to determine total no of characters in the string
        int count=s1.length();
        System.out.println(\"the total no of characters in the above entered string is \"+count);
    }
 }
output
enter the string
 bob is a king maker
 the total no of characters in the above entered string is 19
b)
import java.util.Scanner;
 public class ScannerDemo {
   public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println(\"enter the string\");
        String s1=scanner.nextLine();
        //to store copy of the string
       
        String s2=s1.substring(0, 1);
    //to make duplicate string
        String s3=s2+s1;
        System.out.println(\"the duplicate string is \"+ s3);
    }
 }
output
enter the string
 iam happy
 the duplicate string is iiam happy
c)
import java.util.Scanner;
 public class ScannerDemo {
   public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println(\"enter the string\");
        String s1=scanner.nextLine();
        if(s1.trim().equals(\"i am happy!\"))
        {
            System.out.println(\"the string is \"+\"iam cosc\");
        }else
            System.out.println(\"the original is \"+s1);
    }
 }
output
enter the string
 i am happy!
 the string is iam cosc
d)
import java.util.Scanner;
 public class ScannerDemo {
   public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println(\"enter the string\");
        String s1=scanner.nextLine();
        int length=s1.length();
        String s2=s1.substring(length-3, length);
        System.out.println(\"the string is \"+s2);
       
       
            }
 }
output
enter the string
 iam happy
 the string is ppy


