java chapter-3 practice set answer

Java chapter-3 practice set question



package com.ritesh;

import java.sql.SQLOutput;
import java.util.Scanner;

public class chapter3 {
public static void main(String[] args) {

lowercase();
underscore();
template();
detect();
escape();

}
public static void lowercase() //question no 1
{
System.out.println("Enter your name in uppercase ");
Scanner sc=new Scanner(System.in);
String value=sc.nextLine();
String out=value.toLowerCase();
System.out.println(out);

}

public static void underscore()//question number 2
{
System.out.println("Enter your name ");
Scanner input=new Scanner(System.in);
String value=input.nextLine();
String out1=value.replace(" ","_");
System.out.println(out1);

}

public static void template()//question number 3
{
System.out.println("Enter your name");
Scanner sc=new Scanner(System.in);
String name=sc.nextLine();
String output4="Dear<|"+name+"|>,Thanks a lot\"";
System.out.println(output4);
}
public static void detect()//question number 4
{
System.out.println("Enter a string type value");
Scanner check=new Scanner(System.in);
String check33=check.nextLine();
int find=check33.indexOf(" ");
int find2=check33.lastIndexOf(" ");
int output=(find2+1)-find;
System.out.println(output);


}
private static void escape()//question number 5
{
String name="Dear Harry,\nThis java course is nice\nThanks.";
System.out.println(name);
}
}





Comments