CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2017
    Posts
    182

    [RESOLVED] Code malfunction

    Hello there . I'm still a beginner at java had to write a program to print a hallow rectangle of asterik using for loops with predefined values which means I don't ask user to input anything . This is my code :

    Code:
    public class rectangle { 
    
    public static void rectangle (String  args []) {
    
         for (int i = 0; i < 10 ; i++) {
    
    
               for (int j = 0; j < 4 ; j++) {
    
                   System.out.print("*");
     
               }
      
                 System.out.println("");
    
           }
     
         } 
                  System.out.println("");
     }

    I had an error with main which I didnt know what is it and I don't know if the curly braces is doing an error or something any idea . Thanks for your help

  2. #2
    Join Date
    May 2017
    Posts
    182

    Re: Code malfunction

    I'm not yet using textpad or notepad to compile I was doing it online but there is syntax error I couldn't solve still not used to error any help ? Thanks a lot

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Code malfunction

    Code:
                System.out.println("");
    
           }
     
         } 
                  System.out.println("");
     }
    The second .println() is outside the function rectangle. Do you mean

    Code:
                System.out.println("");
    
           }
           System.out.println("");
     
         } 
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Code malfunction

    By the way, that code prints a solid rectangle. To print a hollow rectangle as required you should first print the top line (all *), then a series of lines consisting of an * at each end and spaces separating them, and finally the bottom line (all * again).

  5. #5
    Join Date
    Aug 2017
    Posts
    36

    Re: Code malfunction

    The first thing you need to do is find out what malfunction code(s) are presently set in the ECM. You can read these malfunction codes in several different ways.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured