Char code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Char code

Whatโ€™s wrong with my code i was trying to write this code from c++ to java : C++: #include<iostream > #include<string.h> #include<conio.h> using namespace std; int main () { char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; cout << "Greeting message: "; cout << greeting << endl; return 0; } To java Public class GREET { public static void main (String[] args){ char greeting [6]={โ€˜Hโ€™,โ€™Eโ€™,โ€™Lโ€™,โ€™Lโ€™,โ€™Oโ€™}; System.out.println(โ€œHello World!โ€): } }

11th Mar 2022, 7:44 PM
Nini
Nini - avatar
2 Answers
0
public class GREET { public static void main (String[] args){ char greeting[]={'H','E','L','L','O'}; //use single quotes ' ' //no need index subscript by this way.. //the other way is //char greating[] = new char[5]; you can add by subscript notation like greating[0] = 'H'; System.out.println(greeting); System.out.println("Hello World!"); //typo mistake, put semicolon } }
11th Mar 2022, 7:52 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
0
//Public public class Greet { public static void main (String[] args){ // [6]={โ€˜Hโ€™,โ€™Eโ€™,โ€™Lโ€™,โ€™Lโ€™,โ€™Oโ€™}; char greeting[]={'H','E','L','L','O'}; System.out.println("Greeting message: "); System.out.println( String.valueOf( greeting) ); } }
11th Mar 2022, 10:34 PM
zemiak