Having Problems writing Big Letters in Java
I cant figure out how to do this but I am suppose to write a java code that is suppose to print a capital H,E,L,L,O. I tried during it in different ways but when I run it it says null instead of saying Hello in big letters and I do not know why it is showing me null instead of what I want. Here is my code:
Code java:
package p2.pkg18;
public class P218 {
private static String finalstringLETTER_H;
private static String finalstringLetter_E;
private static String finalstringLetter_L;
private static String finalstringletter_L;
private static String finalstringLetter_O;
public static void main(String[] args) {
System.out.println(finalstringLETTER_H);
finalstringLETTER_H="* *\n**\n*****\n**\n**\n";
finalstringLetter_E="*****\n*\n*\n*****\n*\n*\n*****\n";
finalstringLetter_L="*\n*\n*\n*\n*\n*****\n";
finalstringletter_L="*\n*\n*\n*\n*\n*****\n";
finalstringLetter_O="****\n* *\n* *\n* *\n* *\n* *\n****";
}
}
Re: Having Problems writing Big Letters in Java
Welcome to the forum.
Variable names should be more descriptive and less misleading, since they are not actually final.
Please see the Announcements page for the use of code tags.
You are attempting to use the variable "finalstringLETTER_H" before it has a value.
Re: Having Problems writing Big Letters in Java
i'm confused what do u mean by that
Re: Having Problems writing Big Letters in Java
private static String finalstringLETTER_H;
^^this has a null value and then you called it
System.out.println(finalstringLETTER_H);
then you assigned it a value
finalstringLETTER_H="* *\n**\n*****\n**\n**\n";
assign it a value then call it
Re: Having Problems writing Big Letters in Java
I got it to work thanks for the help
--- Update ---
sort of
--- Update ---
i did not get the null but when I ran the code i only got the H and not the ello
Re: Having Problems writing Big Letters in Java
As post #4 say's the issue is:
1. You create your variables ( private datatype <Variable Name>; )
2. You display the data of the variables ( null )
3. You initialize/assign data to your variables (<variable name> = "Some type of data (String, char, int, double, float)"
The issue is you are trying to display data that has not been set so it shows it as null because they have not been initialized. The next issue you are getting is you are only displayine one variable. Java doesn't magically know you want to dispaly the rest of the variables. The computer is only going to do what you tell it to do nothing more nothing less.
Another thing mentioned in post #2 is your variable names. The issue here is that there is a difference between:
Code :
private static String s1 = "This string can be changed";
private static final String s2 = "This string is final and cannot be changed."
Re: Having Problems writing Big Letters in Java
Re: Having Problems writing Big Letters in Java
You only have one System.out.println, and it says to print the letter H... You never said to print any other letters so they are not printed.
Any time you make changes to the code and still have a question, post the new version of the code (in code tags).
Re: Having Problems writing Big Letters in Java
r u saying I should make more System.out.printlns
--- Update ---
and how should I have it put in my code
--- Update ---
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package p2.pkg18;
/**
*
* @author Link
*/
public class P218 {
private static String finalstringLETTER_H;
private static String finalstringLetter_E;
private static String finalstringLetter_L;
private static String finalstringletter_L;
private static String finalstringLetter_O;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
finalstringLETTER_H="* *\n* *\n*****\n* *\n* *\n";
System.out.println(finalstringLETTER_H);
finalstringLetter_E="*****\n*\n*\n*****\n*\n*\n*** **\n";
System.out.println(finalstringLetter_E);
finalstringLetter_L="*\n*\n*\n*\n*\n*****\n";
System.out.println(finalstringLetter_L);
finalstringletter_L="*\n*\n*\n*\n*\n*****\n";
System.out.println(finalstringletter_L);
finalstringLetter_O="****\n* *\n* *\n* *\n* *\n* *\n****";
System.out.println(finalstringLetter_O);
}
}
Heres the new code
Re: Having Problems writing Big Letters in Java
As was said in post #2, you should post code in code or highlight tags. Please read the link provided there, learn how, and do it. You can edit your last post, adding the tags of your choice.