More Exercises Java - 01. Data Type Finder
Имам проблем със задачата. Не знаех как да я започна затова гледах в stack overflow и ползвах try statement. Сега не знам какво се чупи, judge дава 70/100. Може да ми дадете насоки да пробвам друго решение на задачата, а не опит с try statement.
Условието:
https://softuni.bg/trainings/resources/officedocument/37510/more-exercise-problem-descriptions-technology-fundamentals-with-java-january-2019/2239
Решение 70/100:
https://pastebin.com/DAUDDsB1
Все още не мога да я напиша 100/100 тази задача.
100 / 100
import java.util.Scanner; public class F12 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); ; while (!(input.equals("END"))){ if(input.matches("([-+]?)[0-9]{0,}")) { System.out.printf("%s is integer type\n", input); } else if (input.matches("([-+]?)[0-9]{0,}\\.([0-9]{0,})?")) { System.out.printf("%s is floating point type\n", input); } else if(input.length() == 1){ System.out.printf("%s is character type\n", input); } else if (input.equalsIgnoreCase("true")|| input.equalsIgnoreCase("false")){ System.out.printf("%s is boolean type\n", input); } else { System.out.printf("%s is string type\n", input); } input = scanner.nextLine(); } } }Здравейте!
Дали някой би могъл да ми каже кой случай или кои случаи пропускам с този код, който дава 60/100?
Много ви благодаря предварително!
https://pastebin.com/gprmARHV
Здравейте колеги, предоставям и моят вариант на задачата => C#
while (input != "END")
{
if (int.TryParse(input, out int integer))
Console.WriteLine($"{input} is integer type");
else if (float.TryParse(input, out float floater))
Console.WriteLine($"{input} is floating point type");
else if (bool.TryParse(input, out bool booler))
Console.WriteLine($"{input} is boolean type");
else if (char.TryParse(input, out char character))
Console.WriteLine($"{input} is character type");
else
Console.WriteLine($"{input} is string type");
input = Console.ReadLine();
}