求一个if判断,若输入的是数字输出数字;若输入的是字符输出字符串
publicclassSystemIn{privatestaticdoubleoutputNum(){Scannerscanner=newScanner(System.i...
public class SystemIn {
private static double outputNum() {
Scanner scanner = new Scanner(System.in);
double n = scanner.nextDouble();
double b = 0.5;
n = Math.pow(n, b);
System.out.println(n);
return n;
}
private static String outputString() {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String str = s.concat("Java");
System.out.println(str);
return s;
}
public static void main(String[] args) {
if(......){ //想写一个判断,若输入的是数字执行outputNum;若输入的是字符执行outputString
outputString();
}
else{
outputNum();
}
}
} 展开
private static double outputNum() {
Scanner scanner = new Scanner(System.in);
double n = scanner.nextDouble();
double b = 0.5;
n = Math.pow(n, b);
System.out.println(n);
return n;
}
private static String outputString() {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String str = s.concat("Java");
System.out.println(str);
return s;
}
public static void main(String[] args) {
if(......){ //想写一个判断,若输入的是数字执行outputNum;若输入的是字符执行outputString
outputString();
}
else{
outputNum();
}
}
} 展开
2个回答
2013-08-04
展开全部
import java.util.Scanner;
public class SystemIn {
private static double outputNum(double s) {
double b = 0.5;
double n = Math.pow(s, b);
System.out.println(n);
return n;
}
private static String outputString(String s) {
String str = s.concat(" Java");
System.out.println(str);
return s;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.next();
try{
double b = Double.parseDouble(s);
outputNum(b);
}catch(NumberFormatException ex){
outputString(s);
}
}
}
public class SystemIn {
private static double outputNum(double s) {
double b = 0.5;
double n = Math.pow(s, b);
System.out.println(n);
return n;
}
private static String outputString(String s) {
String str = s.concat(" Java");
System.out.println(str);
return s;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.next();
try{
double b = Double.parseDouble(s);
outputNum(b);
}catch(NumberFormatException ex){
outputString(s);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询