Knowee
Questions
Features
Study Tools

Given the following method, the output is expected to have Welcome, name repeated based on the count passed in by the user. What is the issue? static String saySomething(String name, int count) { String greeting = ""; for(int i = 0; i < count; i++) { greeting += "Welcome, " + name + "\n"; } return count; }a.)The return statement.b.)The concatenation.c.)The loop.d.)The parameters.

Question

Given the following method, the output is expected to have Welcome, name repeated based on the count passed in by the user. What is the issue? static String saySomething(String name, int count) { String greeting = ""; for(int i = 0; i < count; i++) { greeting += "Welcome, " + name + "\n"; } return count; }a.)The return statement.b.)The concatenation.c.)The loop.d.)The parameters.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The issue is with the return statement. The method is supposed to return a String, but it's currently returning an integer 'count'. It should return 'greeting' instead. So, the correct answer is a.) The return statement.

Similar Questions

Given the following methods: static String saySomething(String name) { return "Hi, " + name; } static String saySomething(String name, int count) { String greeting = ""; for(int i = 0; i < count; i++) { greeting += "Welcome, " + name + "\n"; } return greeting; }Which of the following would need to be called to result in the output:Hi, Sophiaa.)System.out.println(saySomething(1,"Sophia"));b.)System.out.println(saySomething("Sophia",1));c.)System.out.println(saySomething("Hi Sophia"));d.)System.out.println(saySomething("Sophia"));

Given the following method: static String saySomething(String name) { String output = ""; if (name.length() < 5) { output = name + ", your name is short."; } else { output = name + ", your name is long."; } return output; } What would the output be to the screen after following statement? System.out.println(saySomething("Randy"));Randy, your name is long.Randy, your name is short.RandysaySomething("Randy")

How many times will the following code print "Welcome to Instacks"?int count = 0;do { System.out.println("Welcome to Instacks"); count++;} while (count < 10);891011

public class Test {   public static void main(String[] args) {     for (int i = 0; i < args.length; i++) {       System.out.print(args[i] + " ");     }   } } What is the output, if you run the program using java Test 1 2 3?Group of answer choices311 2 31 2 Flag question: Question 15Question 151 ptsWhich correctly creates an array of five empty Strings? Group of answer choicesString[] a = new String [5];String[] a = {"", "", "", "", ""};String[5] a;String[ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null);

public static RETURN_TYPE methodA(int count, String name, double distance, char grade, boolean done) { done = !done; String upperCaseName = name.toUpperCase(); double length = distance; int counter = count + 1; return name;}Group of answer choicescharStringintbooleandouble

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.