java小问题,请多多指教!!
4个回答
展开全部
public class EncodeTest {
/**
* @param args
*/
public static void main(String[] args) {
EncodeTest test = new EncodeTest();
System.out.println(test.encodeChar('e', 3));
String toEncode = "welcome";
System.out.println(test.encodeString(toEncode));
String toDecode = "ezhofrp";
System.out.println(test.decodeString(toDecode));
}
//根据字符进行加密
private char encodeChar(char c,int i){
//先把字符化成ascii码,在把ascii码计算的结果化成字符
return (char)((int)c + i);
}
private String encodeString(String s){
String result = "";
//如果用户输入的是空字符串则直接返回
if(s.length() != 0){
result += s.charAt(s.length() - 1);
for(int i =0; i < s.length() - 1; i++){
result += encodeChar(s.charAt(i), 3);
}
}
return result;
}
private String decodeString(String s){
String result = "";
if(s.length() != 0){
for(int i = 1; i < s.length(); i++){
result += encodeChar(s.charAt(i),-3);
}
result += s.charAt(0);
}
return result;
}
}
//楼主,只有我写了解密算法,你偏心啊! T_T
/**
* @param args
*/
public static void main(String[] args) {
EncodeTest test = new EncodeTest();
System.out.println(test.encodeChar('e', 3));
String toEncode = "welcome";
System.out.println(test.encodeString(toEncode));
String toDecode = "ezhofrp";
System.out.println(test.decodeString(toDecode));
}
//根据字符进行加密
private char encodeChar(char c,int i){
//先把字符化成ascii码,在把ascii码计算的结果化成字符
return (char)((int)c + i);
}
private String encodeString(String s){
String result = "";
//如果用户输入的是空字符串则直接返回
if(s.length() != 0){
result += s.charAt(s.length() - 1);
for(int i =0; i < s.length() - 1; i++){
result += encodeChar(s.charAt(i), 3);
}
}
return result;
}
private String decodeString(String s){
String result = "";
if(s.length() != 0){
for(int i = 1; i < s.length(); i++){
result += encodeChar(s.charAt(i),-3);
}
result += s.charAt(0);
}
return result;
}
}
//楼主,只有我写了解密算法,你偏心啊! T_T
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
System.out.println(new String(new Encrypt().encrypt(new char[]{'w','e','l','c','o','m','e'})));
}
public char[] encrypt(char[] src){
for(int i=0;i<src.length-1;i++){
src[i]=(char) (src[i]+3);
}
char[] target=new char[src.length];
System.arraycopy(src, 0, target, 1, src.length-1);
target[0]=src[src.length-1];
return target;
}
System.out.println(new String(new Encrypt().encrypt(new char[]{'w','e','l','c','o','m','e'})));
}
public char[] encrypt(char[] src){
for(int i=0;i<src.length-1;i++){
src[i]=(char) (src[i]+3);
}
char[] target=new char[src.length];
System.arraycopy(src, 0, target, 1, src.length-1);
target[0]=src[src.length-1];
return target;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args){
char[] array={'w','e','i','c','o','m','e'};
char last=array[array.length-1];
for (int i=array.length-1;i>0; i--) {
array[i]=(char)(array[i-1]+3);
}
array[0]=last;
}
那个答案是错的童鞋;应该是ezhlfrp
char[] array={'w','e','i','c','o','m','e'};
char last=array[array.length-1];
for (int i=array.length-1;i>0; i--) {
array[i]=(char)(array[i-1]+3);
}
array[0]=last;
}
那个答案是错的童鞋;应该是ezhlfrp
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Test {
public static char[] encryp(char[] value){
char[] rs = null;
if(value!=null&&value.length>0){
rs = new char[value.length];
rs[0] = value[value.length-1];
for (int i = 0; i < value.length-1; i++) {
rs[i+1] = (char)((int)value[i]+3);
}
}
return rs;
}
public static void main(String[] args) {
char[] value = {'w','e','i','c','o','m','e'};
char[] rs = Test.encryp(value);
System.out.println(rs);
}
}
--都是没判断非空情况,做完程序员每个判断都注重细节,应该采纳我。
public static char[] encryp(char[] value){
char[] rs = null;
if(value!=null&&value.length>0){
rs = new char[value.length];
rs[0] = value[value.length-1];
for (int i = 0; i < value.length-1; i++) {
rs[i+1] = (char)((int)value[i]+3);
}
}
return rs;
}
public static void main(String[] args) {
char[] value = {'w','e','i','c','o','m','e'};
char[] rs = Test.encryp(value);
System.out.println(rs);
}
}
--都是没判断非空情况,做完程序员每个判断都注重细节,应该采纳我。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询