/*
题目一
从键盘输入一行字符串,回车后单词反转。如 where is a will there is a way 执行后 way a is there will a where
题目二
从键盘输入一串数字,打印最小的那个 124536785 最小的数 1
题目三
给你一组字符串,如asd123fgh456jkl789 得到123456789 有9个数字
以下是实现代码
自己玩着做的
import java.util.*;
import java.lang.*;public class TestMethod {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner as=new Scanner(System.in);
while(true)
{
System.out.println(" \t\t请输入你的选择\n1--题目一 \n2--题目二\n3--题目三\n4--退 出");
int x=as.nextInt();
switch(x)
{
case 1:
TestMethod.Method1();
break;
case 2:
TestMethod.Method2();
break;
case 3:
TestMethod.Method3(" ");
break;
case 4:
System.exit(0);
}
}
}
public static void Method1() //题目一方法
{
System.out.println("请输入一句话,单词以空格分开");
String az=null;
String res="";
Scanner tu=new Scanner(System.in);
az=tu.nextLine();
String[] eg=az.split(" ",-1);
for(int i=eg.length-1;i>0;i--)
{
res+=eg[i]+" ";
}
res +=eg[0];
System.out.println(res);
}
public static void Method2() //题目二方法
{
int[] a=new int[5];
System.out.println("请输入几个数");
Scanner ad=new Scanner(System.in);
String s1=ad.nextLine();
char[] ch=s1.toCharArray();
char min=ch[0];
for(int i=0;i<ch.length;i++)
{
if(min>ch[i])
{
min=ch[i];
}
}
System.out.println(min);
}
public static void Method3(String h) //题目三方法
{
int Count=0;
System.out.println("请输入一串字符");
Scanner scan=new Scanner(System.in);
String str=scan.nextLine();
char[] ch = str.toCharArray();
for(int i=0;i<ch.length;i++){
if(Character.isDigit(ch[i])){
System.out.print(ch[i]);
Count++;
}
}
System.out.println("\n你输入的字符中数字个数:"+Count);
}
}