java 板


LINE

※ 引述《BlackMatrix (BlackMatrix)》之铭言: : 问题是, 我想把一个一串Strings加数字让他变得不一样 : 有四种条件: : The return value will be the ROT13 encoding of the input file. For our : purposes the ROT13 algorithm is defined as follows: : A) If the input is a lower case letter, the output is the lower case : letter plus 13 (with wrap-around, so 'n' becomes 'a') : B) If the input is a upper case letter, the output is the upper case : letter plus 13 (with wrap-around, so 'n' becomes 'a') : C) If the input is a number the output is the number plus 5 (with : wrap-around so '6' becomes '1') : D) If the input is neither letter nor number, the output is the same : as the input ('!' becomes '!' and ' ' becomes ' ') : 也就是说: : 假如我的文件, test.txt里面的一串字是1234那就会变成5678, 然後 : 1a2a3a4a 就会变成 5n6n7n8n 因为a+13会变成n, 大写跟小写都会 : 我现在可以用Scanner跟Reader来读取我的strings, 可是重点是我不会改变他们的数字或 : 是字母 : 问题1: : a+13会变成a13, 那要怎麽才能让他跳13个字母 : 111我+5会变成545454...非常诡异 : 问题2: : 因为我之前有学过C++, 我就想说把Strings当成Array of Chars可是似乎没办法 : 所以我就把他全部都写到 char[] charArray = new char [encodedFile.length()] : 然後利用.charAt(i) <== i 是用for loop : 我现在所有的字母跟数字都在Array of Char里面, 可是我要怎麽用if statement来表示 : A. 如果碰到字母要跳13位 : B. 如果碰到数字要+5 : 目前我A完全不会做, B我这样写, charArray[5] += 5是没办法这样做的. : 因为我似乎把Char当成Int来用, 所以...到底该怎麽办 : 我在网上查了很多资料, 我有用Replace可是完全没办法用 : 我的Code在底下: : http://nopaste.csie.org/a4a9b : 第一次写Java, 买了Just Java2 可是没有帮助我太多 : 因为实在写不出来, 请大家麻烦指点指点 给你一点提示 我下面写的东西. 是把一条 String, 里面的大草变小草, 小草变大草. 把里面用到的东西搞懂, 你的问题也就不难做了 public static String changeCase(String input) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (c >= 'a' && c <= 'z') { c = (char)(c - 32); } else if (c >= 'A' && c <= 'Z') { c = (char)(c + 32); } sb.append(c); } return sb.toString(); } --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.238.156.189
1F:推 BlackMatrix:我似乎有点弄明白一点怎麽做了, 谢谢!!~~~ 02/05 17:00
2F:推 BlackMatrix:我已经把Code做出来了,谢谢,原来字母&数字 => ASCII 02/05 17:46
3F:→ adrianshum:你要搞懂,char 其实也只是一个整数而已 02/06 00:19







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP