Conversion from Boolean to String

//package ch4_package;
import java.io.*;
public class Test_This {
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str_b="java", str ="", str_bool;
try{
System.out.println("---While Loop---");
System.out.print("Please type word java: ");
str = br.readLine();
boolean b;
b = (str.endsWith(str_b))? true : false;
//b = (str.equals(str_b))? true : false;

if (b){
System.out.println("You are got a java: ");
str_bool = b ? "true":"false";
System.out.println("boolean "+ b + "\tstring\t" + str_bool);
}
else
{
System.out.print("sorry you cant' have a character: ");
}
System.out.println();
}//try
catch(NumberFormatException e) { System.out.println("data was blank");}
}
}

In the example we worked out
  • a conversion of Boolean true or false to  string data type.
  • an use of key word "endswith" or "equals", both worked fine.