Skip to content
DragonlordWarlock.com

DragonlordWarlock.com

Home of the Dragonlord Warlock/Norin Nightfire

  • Home
  • About Me
  • Poetry
  • Photos
  • Programming
  • Wallpaper
  • Norin Nightfire
  • Privacy Policy
  • Home
  • Java OOP program to repeat a number of “Hello World” or other user defined string.

Java OOP program to repeat a number of “Hello World” or other user defined string.

Posted on 2019-06-232019-06-23 By Administrator
hello world, java, object oriented programming, objects, programming

class helloOBJ
{
    Integer count;
    String Greeting;
    
    helloOBJ() {
        count = 10;
        Greeting = "Hello World.";
    }
    
    void assignGreeting(String s) {
        if(s!="") Greeting = s;
    }
    
    void assignCount(Integer i) {
        if(i>0) count = i;
    }
    
    public void run() {
        for(Integer i=1; i<=count; i++)
        {
            System.out.printf("[%04d] %s\n", i, Greeting);
        }
    }
}

class helloAPP
{
    public static void main(String[] args)
    {

        Integer pramCount = args.length;
        helloOBJ myObj = new helloOBJ();

        try {
            if(pramCount>=1) {
                Integer j = Integer.parseInt( args[0] );
                myObj.assignCount( j );
            }
            if(pramCount>=2)
                myObj.assignGreeting( args[1] );
            myObj.run();
        } catch (Exception e) {
            System.out.println("An error occured, check arguments.");
        }

    }
}

Syntax

helloAPP [count [custom string]]

Post navigation

❮ Previous Post: Linkable Object C++ Hello World
Next Post: Darksword ❯

You may also like

linux
Converting webp to PNG with a bash script to make life easier.
2014-10-01
Chlo
Chloe
2016-01-03
c++
C++ Prime Numbers
2016-01-10
c++
C++ Hello World using OOP
2019-06-16

Archives

Categories

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Advert

  • Facebook

Copyright © 2026 DragonlordWarlock.com.

Theme: Oceanly News Dark by ScriptsTown