473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do write a method that accepts two arguments: reference to a String object and a

Write a method named showChar. The method should accept two arguments: a reference to a String object and an integer. The integer argument is a character position within the String, with the first character being at position 0. When the method executes, it should display the character at that character position.

This is what I have so far:

public class ShowCharMethod
{
public static void showChar
char letter;
String name = "showChar";
letter = name.charAt();


public static void main(String[] args)
{
String testString = "New York";

showChar(testString, 2);
}

}
Mar 22 '10 #1
1 9698
You should write the code something like that...

Expand|Select|Wrap|Line Numbers
  1. public class ShowCharMethod
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         String testString="New York";
  6.         showChar(testString,2);
  7.     }
  8.     static void showChar(String string, int position)
  9.     {
  10.         char letter=string.charAt(position);
  11.         System.out.println("Character at position "+position+" : "+letter);
  12.     }
  13. }
Mar 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thomas | last post by:
It looks like the String.replace doesn't work in IE6.1. Anyone else has the same problem. I am using newest service package of IE and Win2K. Thanks
15
by: Gabor Drasny | last post by:
Hi all, Could anyone tell me if the following code is guaranteed to work or not? #include <string> #include <iostream> int main() { const char* s = std::string("Hello World").c_str();
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
1
by: Andy | last post by:
Hi, why does with-param fail to send parameters to any templates in a stylesheet that also accepts arguments from the ASP.NET XML control? The argument from the XML control seems to be available...
4
by: MisterPete | last post by:
I created an object that inherits from file and was a bit surprised to find that print seems to bypass the write method for objects inheriting from file. An optimization I suppose. Does this...
1
by: j4me | last post by:
Hi.. I am able to invoke/call a method on a object using reflection. But not able to invoke a method with arguments. Could anyone plz help me on this.
0
ADezii
by: ADezii | last post by:
When you create an ADO Recordset, you should have some idea as to what functionality the Recordset does/does not provide. Some critical questions may, and should, be: Can I add New Records to the...
5
by: creative1 | last post by:
hi, I am new at writing JSP and Servlets. When I compile my serverlet I get follwoing error cannot find mymbol method parseDate(java.lang.String) I have follwoing code: Code: ( text )...
8
by: David Lazos | last post by:
Hi All, I use Contains method of String object to determine if a string variable has another string, like that. *************************** ipAddress.Contains("127.0.0")...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.