参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); for(int i = 0; i < 3; i++) { String t = scanner.next(); f(t); } } public static void f(String a) { if(a.length() > 1) { fun(a); return; } if(a.charAt(0) >= '0' && a.charAt(0) <= '9') fun(Integer.parseInt(a)); else fun(a.charAt(0)); } public static void fun(int a) { System.out.println(a); } public static void fun(char a) { System.out.printf("%d\n", (int)a); } public static void fun(String a) { System.out.println(a.length()); } }
0.0分
9 人评分
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String sentence0=sc.next(); int sentence1=sc.nextInt(); String sentence2=sc.next(); //(char)sentence2; char arr[]=sentence2.toCharArray(); System.out.println(fun(sentence0)); //fun( sentence0); System.out.println(fun(sentence1)); System.out.println(fun(arr[0])); // fun(sentence1); // fun(sentence2) } public static int fun(int a){ return a; } public static int