i am a java beginner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sulthan
    New Member
    • Jan 2008
    • 1

    i am a java beginner

    please explain this program and tell the out put of this program..

    // Classname must be same as filename.
    public class test
    {
    // Variables
    private static String myText = "Hello, World";
    private static String msg;
    private static int myInt = 10;
    // Main - Where the Action Starts
    public static void main(String args[])
    {
    // Print "Hello, World" to the screen.
    System.out.prin tln("Hello, World\n");
    // Multiplication for each value
    for (int i = 0; i <10; i++)
    {
    // Print Calculations to Screen
    System.out.prin tln(calc(i));
    }
    }
    // Handle the calculations
    public static String calc(int timesBy)
    {
    // Put calculation into string
    msg = myInt + " x " + timesBy + "= " + (myInt * timesBy) + "\n";

    // Return Calculation
    return msg;
    }
    }
  • cerise
    New Member
    • Dec 2007
    • 15

    #2
    It simply prints the multiplication table of 10. Its output would be:

    Hello, World

    10 x 0 = 0
    10 x 1 = 10
    10 x 2 = 20
    10 x 3 = 30
    10 x 4 = 40
    10 x 5 = 50
    10 x 6 = 60
    10 x 7 = 70
    10 x 8 = 80
    10 x 9 = 90

    The int variable i are the numbers which are being multiplied to 10. The value of the variable i rises because of the step expression in your for loop. The block after your main block is the method you use to be able to print the calculations (which are these: 10 x 0 = 0, 10 x 1 = 10, etc.). Just ask if you need to anything else explained.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Now you've done the OP's homework and s/he can turn it in as if it were his/her own work.

      What I don't understand is why the OP didn't compile and run the program. It would've
      shown the answer as well.

      kind regards,

      Jos

      Comment

      • cerise
        New Member
        • Dec 2007
        • 15

        #4
        Originally posted by JosAH
        Now you've done the OP's homework and s/he can turn it in as if it were his/her own work.

        What I don't understand is why the OP didn't compile and run the program. It would've
        shown the answer as well.

        kind regards,

        Jos
        I'm sorry, was I not supposed to do that? :( I'll remember the next time.

        And can you tell me what an OP is?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by cerise
          I'm sorry, was I not supposed to do that? :( I'll remember the next time.

          And can you tell me what an OP is?
          An OP is an Original Poster, the one who started the thread and no, we're not
          supposed to do someone else's homework. A few tips and hints are fine though
          but not a boiler plate answer. Read the guidelines (see the 'Help' link in the top
          right corner of this page).

          kind regards,

          Jos

          Comment

          • cerise
            New Member
            • Dec 2007
            • 15

            #6
            Originally posted by JosAH
            An OP is an Original Poster, the one who started the thread and no, we're not
            supposed to do someone else's homework. A few tips and hints are fine though
            but not a boiler plate answer. Read the guidelines (see the 'Help' link in the top
            right corner of this page).

            kind regards,

            Jos
            Again, I apologize. I've read all the guidelines now, and I'll be sure to remember the guidelines the next time.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by cerise
              Again, I apologize. I've read all the guidelines now, and I'll be sure to remember the guidelines the next time.
              Apologies accepted of course; we try to help people to be able to do their own
              work themselves instead of doing it for them. We believe that it has better
              educational value and it keeps away the cheaters ;-)

              kind regards,

              Jos

              Comment

              Working...