java 返回int数组,Java的int数组返回全0

Hello all and thanks for taking the time to look at my question. I'm working on my Java homework (I understand the rules and I don't want you to do my homework, I'm just very stuck and am very confused so please to ban/yell at/poke me)

I have a class called Encryption. I'm calling this class in a Panel, which is being put into a Frame.

I need to read in user input and 'encrypt' that string with my own system using an Array.

I have read my book and searched for answers but I don't know why my INT array is returnign all O's. My Char array is returning the correct Char when I debug it, but my Int array is returning all 0's.

Here is what I have, any advice or suggestions is much appreciated.

Thanks

import java.util.Scanner;

public class Encryption {

private String finalEncryption;

int [] numArray = new int[25];

char[] charArray = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

char current;

//constructor

public Encryption(){

}

public String toString(){

return finalEncryption;

}

public String setEncryption(String entry){

String newEntry = entry.toUpperCase();

//loop to go through each letter in the string

for (int ch = 0; ch < newEntry.length(); ch++)

{

current = newEntry.charAt(ch);

//loop to go through each letter in the alphabet

for (int i=0; i < 26; i++)

{

if(current == charArray[i])

{

int finalEntry = numArray[i];

System.out.println(finalEntry);

}

else if (current == numArray[i])

{

}

}

System.out.println(current);

}

return entry;

}

}

解决方案

An int array defaults to all zero's after you initialize it - this appears to be your case. Nowhere are you setting any values in the int array, you are only initializing it, and then reading it.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值