• Register
1 vote
20 views

Problem:

Hey good people, I hope you are doing good. I was trying to write a program where,  given a string name, e.g. "bob", return a greeting of the form "hello bob!". I was surfing over the internet and find this question from one of the websites. This problem is beyond my understanding. I looking forward to you for a solution.
Thanks.

12 7 7
15,250 points

1 Answer

1 vote

Solution:

Gavin, we can do it by creating a simple string type method. I hope you already know about java methods well. If not, you should learn, and practice it ASAP. Java is an OOP language, so learning the usages methods and objects is a must in java. It makes our program efficient and multi-functional alongside. 

Let’s write a program that works as like as you want:

public class HelloBob {
    public static void main(String[] args) {
        HelloBob test = new HelloBob();
        System.out.println(test.helloString("Bob"));
    }
    public String helloString(String input) {
        return "Hello " + input + "!";
    }
}

Keep exploring and solving problems.
Thanks

13 9 6
94,240 points

Related questions

0 votes
1 answer 191 views
191 views
Problem : I have written following code so far: Scanner scanit = new Scanner(System.in); String strscan = scanit.nextLine(); int x = strscan.length(); int y = strscan.charAt(x/2); System.out.println(strscan.substring(y, x-1)); Because of some reason when ... arrays and other advanced stuff. If someone can tell me how to resolve this issue in the easiest way possible that would be the great help!
asked Nov 26, 2019 alecxe 7.5k points
0 votes
2 answers 389 views
389 views
Problem : I am facing following issue need solution return true if the string "cat" and "dog" appear the same number of times in the given string
asked Nov 13, 2019 peterlaw 6.9k points
0 votes
1 answer 108 views
108 views
Problem : I am trying to print every string in Reverse Double Character way (e.g. string -> ggnniirrttss) import java.util.Scanner; public class ReverseDoubleCharecters { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter ... I get as follows: ss tt rr ii nn gg All double characters are printed on new lines. Anybody has the solution on this?
asked Nov 22, 2019 peterlaw 6.9k points
1 vote
1 answer 416 views
416 views
Problem: I am new in python programming and I have been doing a course on it as a new comer I tried to repeat some char in a string. I wrote a code : def Work(str): for i in range(len(str)): return i * 2 But it does not work . how can I do this?
asked Apr 3 LizzyM 6.1k points
1 vote
1 answer 250 views
250 views
Problem : I am very new to programming. I need to write a program called swapAdj that must accept the array of integers and after that swap those elements at the adjacent indexes. For example consider the elements 0 and 1 are swapped by the program and after ... note if your array has the odd length then the program must keep final element unmodified. Please help me in writing above program.
asked Apr 7 morrisBson 3.2k points