生成mobileNO

本文介绍使用Java实现随机生成手机号及通过用户输入获取渠道名称的方法,并展示了一个批处理文件用于连续执行程序并记录结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1\GetSourceFileLineNo.java

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class GetSourceFileLineNo{

    public static void main(String[] args) {
		getLimitRecord("./result.txt");
    }
	
	public static void getLimitRecord(String filePath){
		BufferedReader br = null;
		String tempStr = "";
		int count = 0;
		int allLineOfFile = getSourceFileLineNo(filePath);
		try{
			br = new BufferedReader(new FileReader(new File(filePath)));
			while((tempStr=br.readLine())!=null){
				if((allLineOfFile - count++)<=10){
					System.out.println(tempStr);
				}
			}
		}catch(IOException e){
			System.out.println("没有该文件或目录");
			e.printStackTrace();
		}finally{
			try{
				br.close();
			}catch(IOException e){
				System.out.println("关闭以前关闭的流无效~!");
				e.printStackTrace();
			}
		}
	}
	
	//Gets all lines of file
	public static int getSourceFileLineNo(String filePath){
		BufferedReader br = null ;
		String tempStr = "";
			int count = 0;
		try{
			br = new BufferedReader(new FileReader(new File(filePath)));
			while((tempStr=br.readLine())!=null){
				count ++;
			}
		}catch(IOException fnf){
			System.out.println("没有该文件或目录");
			fnf.printStackTrace();
			
		}finally{
			try{
				br.close();
			}catch(IOException e){
				System.out.println("关闭以前关闭的流无效~!");
				e.printStackTrace();
			}
		}
		return count;
	}
}

2\MobileRandomNum.java

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;


public class MobileRandomNum {

    public static void main(String[] args) {
		String channelName = channelName();
		System.out.println(channelName);
        System.out.println(startMobileNo() + "-" + endMobileNo());
    }
    
    public static int startMobileNo(){
        int[] mobileStart = {139,138,137,136,135,134,159,158,157,150,151,152,188,130,131,132,156,155,133,153,189,180,177,176};
        Random r = new Random();
        ArrayList<Integer> mobileList = new ArrayList<Integer>();
        for(int i = 0;i<mobileStart.length;i++){
            mobileList.add(mobileStart[i]);
        }
        return mobileList.get(r.nextInt(mobileList.size()));
    }
    
    public static String endMobileNo(){
        Random r = new Random();
        String temp = "";
        for(int i=0;i<8;i++){
			if(i==4){
				temp += "-";
			}
            temp += r.nextInt(10);
        }
        return temp;
    }
	
	public static String channelName(){
		//System.out.println("请输入渠道:1.蚂蚁开户;2.常规开户;3.保单开户;4.融资融券预开户...");
		Scanner scan = new Scanner(System.in);
		int input_result = scan.nextInt();
		String is_result = "";
//		String is_result = String.valueOf(scan.nextInt());
		switch(input_result){
			case 1:
			is_result = "蚂蚁开户";
			break;
			case 2:
			is_result = "常规开户";
			break;
			case 3:
			is_result = "保单开户";
			break;
			case 4:
			is_result = "融资融券预开户";
			break;
			default:
			is_result = "其他";
		}
		return is_result;
	}
}

3\Test.java

import java.util.Scanner;

public class Test{
	public static void main(String[] args){
		Scanner can = new Scanner(System.in);
		String strClass = String.valueOf(can.nextInt());
		System.out.println(strClass.getClass().toString());
	}
}

4\批处理文件内容如下mobileno.bat

@echo off
echo "最近的历史记录~:"
javac -encoding utf8 "D:\randomMobileNo\GetSourceFileLineNo.java"
cd "D:\randomMobileNo\"
for /f "delims=" %%i in ('java GetSourceFileLineNo') do (
    echo %%i
)

:1
echo "请输入渠道:1.蚂蚁开户;2.常规开户;3.保单开户;4.融资融券预开户;5.其他..."
javac -encoding utf8 "D:\randomMobileNo\MobileRandomNum.java"
cd "D:\randomMobileNo\"

for /f "delims=" %%k in ('java MobileRandomNum') do (
    echo %%k
    echo "%%k" -- %date:~0,10% %time:~0,8%>> result.txt 
)
pause
goto 1






5、执行结果写入result.txt

"蚂蚁开户" -- 2017-08-14 17:50:04 
"152-9299-6752" -- 2017-08-14 17:50:04 
"常规开户" -- 2017-08-14 17:50:36 
"180-5163-8699" -- 2017-08-14 17:50:36 
"蚂蚁开户" -- 2017-08-14 17:50:57 
"159-1756-7043" -- 2017-08-14 17:50:57 
"保单开户" -- 2017-08-14 17:51:01 
"133-2187-4830" -- 2017-08-14 17:51:01 
"融资融券预开户" -- 2017-08-14 17:51:08 
"152-5487-5729" -- 2017-08-14 17:51:08 
"蚂蚁开户" -- 2017-08-15 15:18:17 
"157-5977-0146" -- 2017-08-15 15:18:17 
"蚂蚁开户" -- 2017-08-14 17:50:30 
"153-5129-9942" -- 2017-08-14 17:50:30 
"蚂蚁开户" -- 2017-08-15 15:37:04 
"188-5156-5391" -- 2017-08-15 15:37:04 
"蚂蚁开户" -- 2017-08-15 15:37:25 
"132-5877-3524" -- 2017-08-15 15:37:25 
"常规开户" -- 2017-08-15 15:37:28 
"151-4552-4644" -- 2017-08-15 15:37:28 
"保单开户" -- 2017-08-15 15:37:31 
"189-0328-0107" -- 2017-08-15 15:37:31 

 

转载于:https://my.oschina.net/u/3563297/blog/1559722

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值