[英]Unclosed character literal in java
I'm new to java and when I tried to print basic hello world program. 我是java的新手,当我尝试打印基本的hello world程序时。 I am getting following error "Error:(11, 12) java: unclosed character literal "
我收到以下错误“错误:(11,12)java:未关闭的字符文字”
package com.company;
public class Main {
public static void main(String[] args) {
//declare a variable
char a;
a = 'helloworld';
System.out.println("type the char value: " + a);
}
}
Can you please let me know where did I made a mistake ? 您能告诉我我在哪里弄错了吗?
Single quotes can only take one character. 单引号只能包含一个字符。
Change the data type to String
将数据类型更改为
String
String a = "helloworld";
String
represents a string of characters . String
表示字符串 。
See docs: String
and Data types
查看文档:
String
和Data types
First off, the "char" data type can only take a single character. 首先,“ char”数据类型只能使用一个字符。 What you're looking for is the "String" data type.
您要查找的是“字符串”数据类型。
Secondly, as a note on the first, if you create a String you'll need to use double quotes "" rather than single quotes ''. 其次,作为第一个说明,如果创建字符串,则需要使用双引号“”而不是单引号“。
First of all you have to understand all the datatype . 首先,您必须了解所有数据类型 。
char
is use for only store one char char
仅用于存储一个char
String
is use for store many char String
用于存储许多字符
1st way 第一种方式
String a = "helloWorld";
2nd way 第二路
char a[] = {'h', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'};
for(char c : a)
System.out.print(c);
3rd way 第三种方式
System.out.println("HelloWorld");
among all these 1st one is perfect 在所有这些第一个之中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.