I would like to get user Input true or false, but i don't know how to do it. And Convert.ToBool doesn't work. Some ideas ?
10/23/2021 11:28:10 AM
Pacifik3 Answers
New AnswerMaybe you meant to use Convert.ToBoolean()? https://docs.microsoft.com/en-us/dotnet/api/system.convert.toboolean
String st = args[0]; if(st.compareTo(”true”)==0 || st.compareTo(”false”)==0) { boolean b=Boolean.parseBoolean(st); System.out.println(”” + b); } else System.out.println(”not a boolean value”); } The above program is considering strings If the string is either true or false It will be converted to boolean and printed it Otherwise, it is printing a warning message Not a boolean value This code is as per java which is similar to c#
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message