Java打印charArray.toString()

我只是想简单的吧char 数组中的内容打印出来:
public class Test
{
	public static void main(String[] args)
	{

		char[] someArray = { 'J', 'A', 'V', 'A' };

		System.out.println(someArray.toString());
	}
}



结果并不如我预想那样,打印出JAVA,结果反而是”[C@24c21495″这样的。
从官方解释来看,toString函数返回一个字符串,这其中包含了类实例的名字,即@部分,还有该对象的无符号哈希码。等价于:


getClass().getName() + '@' + Integer.toHexString(hashCode())
所以这里,应该改为:


System.out.println(new String(someArray));
Objectives of this Assignment 1. Declare arrays of different types dynamically. 2. Iterate through arrays, processing all of the elements. 3. Write methods with arrays as parameters and return values。 In this assignment you will create your own class and write the methods in it. The class you write is called Main and it has four methods that build arrays and four methods that process arrays. All methods should be public and static. Create a project called P7_4 and a class named Main in a file called Main.java, then follow the instructions below exactly: 1. Write a method named createChars that extracts the characters from a string and builds an array with them. The method takes a parameter of type String and returns an array of characters. Hint: the size of this array is very easy to determine. 2.Write a method called translateChars that takes an array of characters and returns an array of integers with the values that correspond to each element of the character array. For example, the character 'A' will be translated to 65, the character '0' will be translated to 48, and the character '%' will be translated to 37. The integer array returned should be of the same size as the array of characters passed in. 3.Add a main method with the usual signature that instantiates the Main class and tests its methods as follow: public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); // Create arrays char[] charArray = createChars(str); // Test processing System.out.println(Arrays.toString(translateChars(charArray))); in.close(); } Input Specification: There are one line in the input . Output Specification: For each case, output the array that is translated. NOTE: You must use methods to sovle this problem. Sample Input: Java1234!& Sample Output: [74, 97, 118, 97, 49, 50, 51, 52, 33, 38] 代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB 栈限制
03-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值