[散分]

whese 2009-04-18 09:43:00
很容易``绝对是送分``
自定义方法AddMoney,模拟手机充值的过程,在方法中输入“充值卡卡号#充值卡密码#充值的手机号码”字符串,从中取出要充值的手机号码,向用户确认是否要充值,输入1确定,输入其他任意键放弃,方法返回充值是否成功,在Main()方法中输出结果`

提示:
(1)方法不需要参数,方法的返回值是一个布尔类型;
(2)从输入的字符串中取出手机号码,要先找到最后一个“#”的位置,“#”后面的部分就是手机号码,
...全文
196 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
tang_fu 2009-04-18
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
namespace Handset
{
class Program
{
static void Main(string[] args)
{

bool result = AddMoney();
if (result == true)
{
Console.WriteLine("充值成功");
}
else
{
Console.WriteLine("充值失败");
}
Console.ReadLine();


}
private static bool AddMoney()
{

string num;//输入的字符串
int position;//“#”在地址中的索引
string handsetNum="";//手机号


Console.Write("请输入充值卡号#充值卡密码#充值的手机号码:");
num = Console.ReadLine();
position = num.LastIndexOf("#");
if (position > 0)
{
//提取手机号
handsetNum = num.Substring(position);

}
else
{
Console.Write("请正确输入:");
}
Console.WriteLine("你要为{0}充入话费?确认请按1,取消请按任意键:",handsetNum);

string command = Console.ReadLine();
//char key = Console.ReadKey();
//if (key == 49) //数字键'1'的ASCII码为49
//{
// Console.WriteLine("冲值成功!");
//}
//else
//{
// Console.WriteLine("您放弃了冲值!");
//}
return command == "1";

}
}
}


AuC 2009-04-18
  • 打赏
  • 举报
回复


static void Main(string[] args)
{

bool result = AddMoney();
if (result == true)
{
Console.WriteLine("充值成功");
}
else
{
Console.WriteLine("充值失败");
}
Console.ReadLine();




}
private static bool AddMoney()
{

string num;//输入的字符串
int position;//“#”在地址中的索引
string handsetNum="";//手机号


Console.Write("请输入充值卡号#充值卡密码#充值的手机号码:");
num = Console.ReadLine();
position = num.LastIndexOf("#");
if (position > 0)
{
//提取手机号
handsetNum = num.Substring(position);

}
else
{
Console.Write("请正确输入:");
}
Console.WriteLine("你要为{0}充入话费?确认请按1,取消请按任意键:",handsetNum);

string command = Console.ReadLine();
//char key = Console.ReadKey();
//if (key == 49) //数字键'1'的ASCII码为49
//{
// Console.WriteLine("冲值成功!");
//}
//else
//{
// Console.WriteLine("您放弃了冲值!");
//}
return command == "1";

}

whese 2009-04-18
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Text;

namespace Handset
{
class Program
{
static void Main(string[] args)
{

bool result = AddMoney();
if (result == true)
{
Console.WriteLine("充值成功");
}
else
{
Console.WriteLine("充值失败");
}
Console.ReadLine();




}
private static bool AddMoney()
{

string num;//输入的字符串
int position;//“#”在地址中的索引
string handsetNum="";//手机号


Console.Write("请输入充值卡号#充值卡密码#充值的手机号码:");
num = Console.ReadLine();
position = num.LastIndexOf("#");
if (position > 0)
{
//提取手机号
handsetNum = num.Substring(position);

}
else
{
Console.Write("请正确输入:");
}
Console.WriteLine("你要为{0}充入话费?确认请按1,取消请按任意键:",handsetNum);

string command = Console.ReadLine();
//char key = Console.ReadKey();
//if (key == 49) //数字键'1'的ASCII码为49
//{
// Console.WriteLine("冲值成功!");
//}
//else
//{
// Console.WriteLine("您放弃了冲值!");
//}
return command == "1";

}
}
}



我自己也写出来一个``还好看了二楼的`不然还真写不出``- -我太笨了`
ACMAIN_CHM 2009-04-18
  • 打赏
  • 举报
回复

收分
陌上花花 2009-04-18
  • 打赏
  • 举报
回复
帮顶下
whese 2009-04-18
  • 打赏
  • 举报
回复
7楼的``
- -你写的那个`好像出错了`
错误 1 无法将类型“System.ConsoleKeyInfo”隐式转换为“char” E:\C#\Handset\Handset\Program.cs 51 24 Handset
kkun_3yue3 2009-04-18
  • 打赏
  • 举报
回复
都是提取手机号码,可以的
蓝海D鱼 2009-04-18
  • 打赏
  • 举报
回复
收分
whese 2009-04-18
  • 打赏
  • 举报
回复
2楼的
string mobile = Regex.Match( original, @"#\d{11}$" ).Value;
5楼的
string mobile =str.Substring(str.LastIndexOf("\\")+1);


谁和我说下这两句是什么意思呢`我是新手看不明白``这样写可以取出手机号吗`/??
「已注销」 2009-04-18
  • 打赏
  • 举报
回复
你不是都知道该怎么办了吗?再加一个获取你按下键是否为“1”的语句
char key = Console.ReadKey();
if (key == 49) //数字键'1'的ASCII码为49
{
Console.WriteLine("冲值成功!");
}
else
{
Console.WriteLine("您放弃了冲值!");
}
sky_teamsoft 2009-04-18
  • 打赏
  • 举报
回复
Up
wuyq11 2009-04-18
  • 打赏
  • 举报
回复
static bool AddMoney() {
Console.Write( "充值卡卡号#充值卡密码#充值的手机号码" );
string str= Console.ReadLine();
string mobile =str.Substring(str.LastIndexOf("\\")+1);
Console.WriteLine( "您要充值的手机号码为:" + mobile + "\r\n确认请按1,取消请按0" );
string command = Console.ReadLine();
return command == "1";
}
ztmdsbt 2009-04-18
  • 打赏
  • 举报
回复
帮顶哦.
whese 2009-04-18
  • 打赏
  • 举报
回复
- -看看还有没有其他答案啦
kkun_3yue3 2009-04-18
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1 {
class Program {
static void Main( string[] args ) {
bool result=AddMoney();
Console.WriteLine(result.ToString());
Console.ReadLine();
}

static bool AddMoney() {
//充值卡卡号#充值卡密码#充值的手机号码
Console.Write( "充值卡卡号#充值卡密码#充值的手机号码" );
string original = Console.ReadLine();
string mobile = Regex.Match( original, @"#\d{11}$" ).Value;
Console.WriteLine( "您要充值的手机号码为:" + mobile + "\r\n确认请按1,取消请按0" );
string command = Console.ReadLine();
return command == "1";
}
}
}


「已注销」 2009-04-18
  • 打赏
  • 举报
回复
哈哈,枪到沙发了

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧