-
October 11th, 2017, 03:15 PM
#1
[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
-
October 11th, 2017, 06:08 PM
#2
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
-
October 12th, 2017, 04:28 AM
#3
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)
-
October 12th, 2017, 09:32 AM
#4
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).
-
October 13th, 2017, 01:49 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|