Question

I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...

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.

Homework Answers

Answer #1

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 :).

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(This is for Java) For this I need to make a loop that will sum the...
(This is for Java) For this I need to make a loop that will sum the numbers from 3 to 22 public class Practice25 {    public static void main (String [] args) {            int sum = 0;           //The loop will go here      sum += i;     System.out.println ("Sum from 3 to 22 is: " + sum);    } }
Hello, I am trying to create a Java program that reads a .txt file and outputs...
Hello, I am trying to create a Java program that reads a .txt file and outputs how many times the word "and" is used. I attempted modifying a code I had previously used for counting the total number of tokens, but now it is saying there is an input mismatch. Please help! My code is below: import java.util.*; import java.io.*; public class Hamlet2 { public static void main(String[] args) throws FileNotFoundException { File file = new File("hamlet.txt"); Scanner fileRead =...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
I am having some trouble writing some java code involving strings. I have included the code...
I am having some trouble writing some java code involving strings. I have included the code provided by my professor below. that has the instructions in it as well public class StringExercise { public static void main(String[] args) { String given = "The quick brown fox jumped over the moon!"; String given2 = "mary"; String given3 = "D"; //Write a Java code snippet to check (print a boolean) whether the given String ends with the contents of "oon!", see endsWith...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
This is Java programing.Modify this Java code,so that each franchise can assign and print their own...
This is Java programing.Modify this Java code,so that each franchise can assign and print their own burger price.The programing have at least three franchises. (Use abstract) class newBurger { public newBurger() { } public void salmonBurger(){    System.out.println("salmonBurger $5.99");    System.out.println("Kcal: 294"); } public void clamBurger(){    System.out.println("clamBurger $4.99");    System.out.println("Kcal: 200"); } public void oysterBurger(){    System.out.println("oysterBurger $3.50");    System.out.println("Kcal: 125"); } } class franchise1 extends newBurger { String name = "franchise #1"; public franchise1() { } } public...