Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Having Problems writing Big Letters in Java

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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:

    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****";
        }
    }
    Last edited by jps; September 5th, 2013 at 04:14 PM. Reason: code tags


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having Problems writing Big Letters in Java

    i'm confused what do u mean by that

  4. #4
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default 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

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default 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:
    private static String s1 = "This string can be changed";
    private static final String s2 = "This string is final and cannot be changed."

  7. #7
    Junior Member
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having Problems writing Big Letters in Java

    what do you mean by this

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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).

  9. #9
    Junior Member
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  10. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,151
    My Mood
    Mellow
    Thanks
    187
    Thanked 660 Times in 647 Posts

    Default 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.

Similar Threads

  1. help with writing a letters encoding program
    By Samedge20 in forum Object Oriented Programming
    Replies: 8
    Last Post: July 14th, 2013, 09:18 AM
  2. Problems in reading/writing from/to a socket
    By Fabgio in forum Java Networking
    Replies: 5
    Last Post: July 2nd, 2013, 01:33 PM
  3. Replies: 3
    Last Post: January 25th, 2013, 05:53 AM
  4. Big problems with my hasNext method and outer loop! Please help!
    By Eclecstatic in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 26th, 2012, 08:55 AM
  5. big problems bounding() in Java2d with LineBreakMeasurer.
    By fenderman in forum AWT / Java Swing
    Replies: 0
    Last Post: July 27th, 2009, 01:15 PM