+ 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!â): } }
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
}
}
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) );
}
}