+ 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 Respostas
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