CrazyEngineers
  • A tricky program 2 to Java Beginners,

    ms_cs

    Member

    Updated: Oct 25, 2024
    Views: 1.3K
    <a href="https://javacoderblog.blogspot.com/2010/05/tricky-program-1-to-java-beginners.html" target="_blank" rel="nofollow noopener noreferrer">Java Programmer's Blog: A tricky program 2 to Java Beginners,</a>

    Question:- You should bring the output by not modifying the main method,The output is "Great Java Programmer".

    class NMM //No main method
    {
    public static void main(String []args)
    {
    System.out.println(“Java”);
    }
    }
    Seems tricky? Anybody?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberJun 8, 2010

    May be this code is answer

    class NMM //No main method
    {
    static
    {
    System.out.println("Great Java Programmer");
    System.exit(0);
    }
    public static void main(String []args)
    {
    System.out.println("Java");
    }
    }[IMG]file:///C:/Users/Inder/AppData/Local/Temp/moz-screenshot-5.png[/IMG][IMG]file:///C:/Users/Inder/AppData/Local/Temp/moz-screenshot-6.png[/IMG]
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJun 8, 2010

    goyal420
    May be this code is answer

    class NMM //No main method
    {
    static
    {
    System.out.println("Great Java Programmer");
    System.exit(0);
    }
    public static void main(String []args)
    {
    System.out.println("Java");
    }
    }[IMG]file:///C:/Users/Inder/AppData/Local/Temp/moz-screenshot-5.png[/IMG][IMG]file:///C:/Users/Inder/AppData/Local/Temp/moz-screenshot-6.png[/IMG]
    Nice, the main method must run buddy
    Are you sure? This action cannot be undone.
    Cancel
  • mohan_185

    MemberJun 13, 2010

    I am new to java programming . may be this solution may not be optimal
    class NMM
    {
    public static void main(String []args)
    {
    System.out.println("java");
    }


    static
    {
    System.out.println("great");
    NMM.main(null);
    System.out.println("programmer");
    System.exit(0);

    }

    }
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberJun 15, 2010

    @Mohan Good job done

    @ms_cs Are you sure output should be "Great Java Programmer" [in one single line] and not in multiple lines like
    "Great
    Java Programmer"
    or
    "Great
    Java
    Programmer"
    Are you sure? This action cannot be undone.
    Cancel
  • mohan_185

    MemberJun 15, 2010

    @sookie thanks buddy
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJun 15, 2010

    @mohan_185 : Nice buddy..

    @sookie : yes output should be in one line..
    Are you sure? This action cannot be undone.
    Cancel
  • mohan_185

    MemberJun 15, 2010

    @ms_cs
    output cant be in online because
    System.out.println(“Java”);

    After printing java it will go to the next line then only it will print programmer
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJun 15, 2010

    cool Mohan, there is a trick,or may be a hack 😉,
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberJun 16, 2010

    [Edit: Removed..Sorry for spamming]

    @ms_cs Well I am giving up. Today realised "I am not even a Java beginner..so sad" 😔 Send me the answer through PM if can't post it here. 😀
    Are you sure? This action cannot be undone.
    Cancel
  • abhinaykumar

    MemberJun 19, 2010

    public class NMM
    {
    static
    {
    System.out.print("Great ");
    NMM.main(null);
    System.out.print("Programmer ");
    System.exit(0);

    }
    public static void main(String []args)
    {
    System.out.print("Java ");

    }

    }

    the output is "Great Java Programmer" in single line
    the logic is nothing but using println prints the message in new line if u use only print in sop statement u can get it in single line buddy....
    we cannot print the output in single line coz in the main method u used the println statement for java so its impossible to get the desired output without changing main method.....
    Are you sure? This action cannot be undone.
    Cancel
  • mathew720

    MemberJun 19, 2010

    dude i would love to learn Java how , in much time could i learn it , which site would you opt , funny part is i am not even an engineer

    , i have few basics of c++ long back in high school ,its interesting i guess answer i am waiting for an answer too
    Are you sure? This action cannot be undone.
    Cancel
  • abhinaykumar

    MemberJun 20, 2010

    is there really a trick to print the way with out changin the main method if yes please send me the answer...
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberJun 21, 2010

    abhinaykumar
    is there really a trick to print the way with out changin the main method if yes please send me the answer...
    As per me, following program works without changing the main method but I am still not sure it is the answer. But still feeling good after trying atleast something of my own 😁
    
    import java.io.OutputStream;
    import java.io.PrintStream;
    
    /**
     *
     * @author sookie
     */
    public class Print_GreatJavaProgrammer {
    public static void main(String []args)
    {
    System.out.println("Java");
    }
                
    static 
    {
     PrintStream printStreamOriginal=System.out;
    
     /* Setting the out member of the System class in such a way that it prints nothing*/ 
     System.setOut(new PrintStream(new OutputStream(){
    			public void write(int b) {
    			}
    		}));
    
        /* Calling the main method */
       Print_GreatJavaProgrammer.main(null);
        
       /* Re-setting it so that it prints in actual manner */ 
       System.setOut(printStreamOriginal);
       System.out.println("Geat Java Programmer");
       System.exit(0);
    }
    
    }
    
    Feel free to ask if have any questions regarding it. 😀

    * Still waiting for the actual answer :-| *
    Are you sure? This action cannot be undone.
    Cancel
  • abhinaykumar

    MemberJun 21, 2010

    hai Sookie can u xplain the statements u used in the static method........
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJun 21, 2010

    Sookie:- nicely you have done.
    Let me post mine's solution

    import java.io.*;
    public class NMM
    {
    static
    {

    final PrintStream out = System.out;

    PrintStream newOut = new PrintStream(out)
    {

    public void println(String str1)
    {
    print("Great ");
    print(str1);
    super.println("Programmer");
    }
    };

    System.setOut(newOut);
    }


    public static void main(String [ ]argums)
    {
    System.out.println("Java ");
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 21, 2010

    @ms_cs Can you please explain this program?
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJun 21, 2010

    goyal420
    @ms_cs Can you please explain this program?
    @goyal: I just have written code for overriding the method println(String) which will be used in the main mehtod,,that;s it
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberJun 22, 2010

    abhinaykumar
    hai Sookie can u xplain the statements u used in the static method........
    Sure !
    System.setOut(new PrintStream(new OutputStream(){
    public void write(int b) {
    }
    }));
    In the above statement, I am making System.out to behave in such a manner that it prints/writes nothing as output in console. It is simply overriding the write() method of OutputStream abstract class. The concept that is used above is called as "Anonymous inner classes". Alternatively you could do is , create a class that extends "OutputStream" class and then overrides its "write" method -just like I did in above statement and then instantiate that implementing class and pass as an argument to "PrintStream" class .

    Well, this was syntax related. Now what exactly that statement does is -
    If you look at System.out.println then System.out is a PrintStream type of class which calls println() method of PrintStream to write anything on console and println() calls "write" method internally . If you look at the API carefully then you will find that write() method is being overriden from FilterOutputStream class which ultimately extends OutputStream class. *sighs* Hope you understood the concept [As per me it was not at all a problem for JAVA BEGINNER until the beginner knows the ready made answer. 😀 ]

    Now coming to the next line
    Print_GreatJavaProgrammer.main(null);
    Now this triggers the main() method and tries to print "Java" from the main() method but because we have already set the write() method as below
    public void write(int b) {
    }
    So, it will not print "Java" in the console.

    Now coming to next line
    System.setOut(printStreamOriginal); //where PrintStream printStreamOriginal=System.out;
    Now using above statement , I am again setting the System.out value to the one default provided by Java folks. System.setOut(System.out). It will revert back the System.out to original PrintStream write() method. No overriding, nothing. Only default values.

    Now coming to last line
    System.out.println("Geat Java Programmer");
    The above statement of static block works as normal Java program because we have already re-set the System.out to default print() method.

    Finally System.exit(0) to exit from this program and thread hopefully *just kidding* 😀

    Hope you got the concept and if still any questions, feel free to ask. 😀 I think solution by ms_cs is quite easy to understand but will work only for few cases.
    Are you sure? This action cannot be undone.
    Cancel
  • abhinaykumar

    MemberJun 22, 2010

    thanks sookie
    Are you sure? This action cannot be undone.
    Cancel
  • abhinaykumar

    MemberJun 22, 2010

    import java.util.Scanner;
    public class Manager
    {
        public static void main(String[] args)
        {
            String[] units={ " ","one","two","three","four","five","six","seven","eight","nine" };
            String[] teens={ " ","ten","eleven","twele","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
            String[] tens={ " ", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred" };
            Scanner nte=new Scanner(System.in);
            System.out.println("Enter any Value from One to Hundred");
            try
            {
            int num=Integer.parseInt(nte.next());
            if(num<10)
            {
                int k=num % 10;
                System.out.println(units[k]);
            }
            else
            {
                if(num<19)
                {
                    int m,n;
                    m=num/10;
                    n=num%10;
                    int l=n+m;
                    System.out.println(teens[l]);
                }
                else
                {
                    if(num>19)
                    {
                        int a,b;
                        a= num/10;
                        b= num % 10;
                        System.out.println(tens[a-1]+units);
                    }
                    else
                    {
                      
                    }              
                }
            }
            }
            catch(NumberFormatException ex)
            {
                        ex.printStackTrace();
            }
            }
    }


    hai guys can anyone tellme how to reduce lines in this program
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberJun 22, 2010

    Try the below one - if your all cases still working or not
    
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public
    [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Manager {[/SIZE]
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] main(String[] args) {[/SIZE]
    [SIZE=2]String[] units = { [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"one"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"two"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"three"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"four"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"five"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"six"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE]
    [SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"seven"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"eight"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"nine"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] };[/SIZE]
    [SIZE=2]String[] teens = { [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ten"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"eleven"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"twele"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"thirteen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE]
    [SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"fourteen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"fi fteen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"sixteen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"seventeen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"eighteen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE]
    [SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"nineteen"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] };[/SIZE]
    [SIZE=2]String[] tens = { [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"twenty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"thirty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"fourty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"fifty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"sixty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE]
    [SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"seventy"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"eighty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ninety"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"hundred"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] };[/SIZE]
    [SIZE=2]Scanner nte = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Scanner(System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]in[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Enter any Value from One to Hundred"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] num = Integer.[I]parseInt[/I](nte.next());[/SIZE]
    [SIZE=2][/SIZE] 
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (num>1 && num < 10) {[/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println(units[num%10]);[/SIZE]
    [SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (num>1 && num < 19) {[/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println(teens[(num/10)+(num%10)]);[/SIZE]
    [SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (num>1 && num > 19) {[/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println(tens[num/10 - 1] + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+units[num%10]);[/SIZE]
    [SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Invalid Number"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2]}[/SIZE][/LEFT]
     
    [LEFT][SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (NumberFormatException ex) {[/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Number Format Exception"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE][/LEFT]
    
    I guess you should have kept it in separate thread so that we can try to extend this program problem further. 😀

    [/LEFT]
    Are you sure? This action cannot be undone.
    Cancel
  • abhinaykumar

    MemberJun 23, 2010

    okay sookie
    Are you sure? This action cannot be undone.
    Cancel
  • Malhar

    MemberMar 23, 2011

    class Test1
    {
    static{
    System.out.print("Great");
    }
    public static void main(String []args)
    {
    System.out.println("Java");
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • TheV

    MemberApr 1, 2011

    import java.util.Scanner;
    class Manager{
    public static void main(String[] args){
    String[] units={ "","one","two","three","four","five","six","seven", "eight","nine","ten","eleven","twele","thirteen","fourteen","fi fteen","sixteen","seventeen","eighteen","nineteen","twenty" };
    String[] tens={ " "," ","twenty ", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred" };
    Scanner nte=new Scanner(System.in);
    System.out.println("Enter any Value from one to Hundred");
    try{
    int num=nte.nextInt();
    if(num<=20){
    System.out.println(units[num]);
    }
    else{
    int a= num/10;
    int b= num % 10;
    System.out.println(tens[a]+" "+units[b]);
    }
    }
    catch(Exception ex){
    System.out.println("Invalid Input");
    }
    }
    }
    I work out this way....
    Are you sure? This action cannot be undone.
    Cancel
  • Hemant Patel

    MemberMay 3, 2011

    // another logic 😉
    import java.util.*;
    class nmm
    {
    public static void main(String ...k)
    {
    System.out.println("Java");
    }
    nmm() {
    System.out.println("Great Java Programer");
    System.exit(0);
    }
    static nmm jcore=new nmm();
    }
    Are you sure? This action cannot be undone.
    Cancel
  • spiky

    MemberMay 11, 2011

    class NMM //No main method
    {
    init
    {
    System.out.print("Great");
    }
    public static void main(String []args)
    {
    System.out.print(“ Java”);
    show();
    }
    static void show()
    {
    System.out.print(" Programmer");
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Agam Agarwal

    MemberAug 13, 2011

    the solution is easy
    just stop the main method from executing and print what u want to print
    can be done as follows

    class NMM //No main method
    {
    static
    {System.out.println("Great Java Programmer");
    System.exit(0);
    }
    public static void main(String []args)
    {
    System.out.println("Java");
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • TheV

    MemberAug 14, 2011

    You can do this way tooo...

    class NMM{
    static{
       System.out.print("Great");
       NMM.main(null);
      System.out.print("Programer");
      System.exit(1);
    }
    public static void main(String []args){
        System.out.println("Java");
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Java freak

    MemberSep 10, 2015

    public class helloworld{
                   
    static
    {
    System.out.print("Great ");
    }                   
    public static void main(String args[])
    {
               
    System.out.println("java ");
                           
    }
        static
    {
    System.out.print("Devleoper");
    }
    
    }
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register