I am writing code in java to make the design below.
:-):-):-):-):-):-) :-):-):-):-):-):-) :-):-):-):-):-):-)
:-):-):-):-):-):-) :-):-):-):-):-):-) :-):-):-):-):-):-)
I already have this much
public class Main {
int WIDTH = 0;
double HEIGHT = 0;
public static void drawSmileyFaces() {
System.out.println(" :-):-):-):-):-):-)");
}
public static void main (String[] args) {
for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) {
for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) {
drawSmileyFaces();
}
}
}
}
I am pretty sure that alot of this is wrong and I would like some help so that my program displays the above output. Thanks for your time.
Ans ). It is just a small error. Firstly, in the drawSmileFaces() function, you are using System.out.println(). This will print the given input string and moves to the next line.
But we want it to print for three times in a single line. So instead of prinln(), you should use print() here.
When you printed first three strings of smilies, now you wan to move to next line. So just println() some empty string after inner loop. This will move the pointer to the next line. And then you'll get three consecutive strings of smilies in a single row.
Below is the editted code with 2 edits marked.
public class Main {
int WIDTH = 0;
double HEIGHT = 0;
public static void drawSmileyFaces()
{
System.out.print(" :-):-):-):-):-):-)"); // edit no 1
}
public static void main (String[] args)
{
for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) {
for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++)
{
drawSmileyFaces();
}
System.out.println(""); // edit no 2
}
}
}
Here's a Sample OUTPUT :-
Hope it helped! Feel free to ask any doubt in comments. Don't forget to upvote if it helped :).
Get Answers For Free
Most questions answered within 1 hours.