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 =...
What's wrong with this code? #Java Why I am getting error in : int BusCompare =...
What's wrong with this code? #Java Why I am getting error in : int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); public class TypeComparator implements Comparator<Type> { @Override public int compare(Type o1, Type o2) { // return o1.name.compareTo(o2.name); int NameCompare = o1.name.compareTo(o2.name); int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); // 2-level comparison using if-else block if (NameCompare == 0) { return ((BusCompare == 0) ? NameCompare : BusCompare); } else { return NameCompare; } } } public class Type implements Comparable<Type> { int id; String name; int...
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...
Java program question! If I pass null to a method, how can I use the passed...
Java program question! If I pass null to a method, how can I use the passed value to compare. Here is example code, it might be wrong, please make it could run on eclipse. Public class hw{ public static void main (String args[]) { method1(); } private static void method1() { System.out.println(method(null)); } public static String method(int[] a) { return null; } What I want to get in the output is just "()". It is not just to type the...
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 =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT