• Register
1 vote


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.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote


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();
    public String helloString(String input) {
        return "Hello " + input + "!";

Keep exploring and solving problems.

13 9 6
94,240 points

Related questions

0 votes
1 answer 233 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 683 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 147 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
0 votes
1 answer 18 views
Problem: The above formula is derived from shoelace formula. So we will check if the area formed by the triangle is zero or not. Below is the implementation of the above approach Java
asked Dec 2, 2020 Mashhoodch 6.3k points
0 votes
1 answer 6 views
Problem: Hello Developers! I am new to the world of programming and I started learning Java at an academy. My teacher gave us an assingment in which we have to find the index of last occurrence of a character in a string. The program should return the ... those solutions. If someone has better solution then kindly explain or else please explain what substrings are and how I can use it. Thanks
asked Nov 29, 2020 Code Learner 5.5k points
1 vote
1 answer 731 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, 2020 LizzyM 6.1k points
0 votes
1 answer 2 views
Is there any Java implementation example?
asked 8 hours ago TeamScript 11.1k points
0 votes
1 answer 392 views
Problem : I am completely stuck on this problem Given an array of ints, return True if the array contains a 2 next to a 2 somewhere. has22([1, 2, 2]) → True has22([1, 2, 1, 2]) → False has22([2, 1, 2]) → False I know the basic idea but I am unable to implement it. ... this, eg. graph, search? def has22(mynums): for l in mynums: if ( (mynums[l] = 2) and (mynums[l+1] = 2) ) return True return False
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 19 views
Why is this so?
asked Jan 1 TeamScript 11.1k points
1 vote
1 answer 370 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, 2020 morrisBson 3.2k points