三道java练习题的菜单方式实现

/*

题目一

从键盘输入一行字符串,回车后单词反转。如   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);
      
   }
   }



 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值