Concatinating numbers with a string...sort of

Well I've got an assignment that says this "Write a method called multiConcat that takes a string and an interger as parameters. Return a string that consists of the string parameter concatenated with itself count time, where count is the integer parameter. For example, if the parameter vales are 'hi" and 4, the return value is "hihihihi". Return the original string if the interger parameter is less than two.
So I've tried a couple of things that I thought would work with my small amount of CS courses, but I have not been able to come up with a resolution for this assignment yet. I do not want anyone to post any time of code yet. All I ask for is for someone to point me in the correct direction with some kind of a learning document etc.

for that the answer is
class MyClass{
     StringBuffer string1=null;
public      StringBuffer myMethod(String string , int number){
string1=new StringBuffer(string);
          if (number<2){
               return string1;
          }else{
               while(number!=1){
                    string1.append(string);//here string is String and string1 is StringBuffer tehn only we can get coorect data.then u will get output hihihihi for input hi,4
                    //try it by keeping both of type stringBuffer, u will get out put hihihihihihihihi for input hi,4
                    --number;
               return string1;
class FirstProgram {
     public static void main(String[] args) {
          String string=args[0];
          int number=Integer.parseInt(args[1]);
          System.out.println("string ="+string+" "+"number ="+number);
          StringBuffer result=(new MyClass()).myMethod(string,number);
          System.out.println("final output is"+result);
}

Similar Messages

  • Sorting an array of numbers with loops

    Hi, i'm looking for a way to sort an array or numbers with loops.
    my array looks like this. int[] numbers = {5,2,7,9,1}
    i know how to use the "sort" method and i want to do it without the sort method, but i am not very clear on the logic behind it.
    by the end it should look like this, {1,2,5,7,9}
    i know 2 loops are used, can you please give me a logic to work with.
    i have started the loops but what to do inside???
    int temp;
    for (int i=0; i<numbers.length; i++){
    for (int j=1; j<numbers; j++){
    if (numbers<numbers[j])
    temp = numbers[i];
    Any suggestions i will be thankful for.
    thank you.

    fly wrote:
    no not really a homework question.. i want to improve my logic because it is very poor at the moment.. but i'm sure someone knows how to sort an array with loops only.Yes, we do know how to do it, I once wrote a heapsort in assembly code, as a real work project. But you rarely get a project like that the good ones were all done years ago.
    All the algorithms I suggested you look at use loops. the simplest and slowest is the bubble sort. This one runs by comparing values and swapping their locations, the wikipedia article http://en.wikipedia.org/wiki/Bubble_sort has the algorithm.

  • Comparing string delimited by semicolon in a column with another string

    Hi
    I have requirement like comparing a column which contains the string delimited by semi colon with a string delimited by semicolon. i.e. comparing the multiple values with multiple values.for this purpose i am using the following code
    select ams.application_id,it_mgmt_chain
    FROM tb_ams038_application ams,THE
    (SELECT CAST
    (Appmgmt_Str_To_Table
    (NVL (ams.it_mgmt_chain,
    ) AS appmgmt_tabletype_string
    FROM DUAL
    AND (COLUMN_VALUE IN ( SELECT COLUMN_VALUE
    FROM THE
    (SELECT CAST
    (Appmgmt_Str_To_Table
    (nvl(NVL (replace('1234;8383;83939;93939',',',';'),
    ams.it_mgmt_chain
    ) AS appmgmt_tabletype_string
    FROM DUAL
    here in the above it_mgmt_chain has the string containing numbers seperated by semi colon. and the Appmgmt_Str_To_Table function used to split the string and return it in the form of list. and appmgmt_tabletype_string is a varray which is created for spliting and storing purpose.
    Can anyone please suggest the best way to do this task as the above code is giving a performance issue.

    This example uses a "|" not a semicolon but it leverages the REGEXP_SUBSTR, SUBSTR, LENGTH to perform a parsing action.
    http://blog.mclaughlinsoftware.com/plsql-programming/a-result-cache-function-returning-a-collection/
    You may wish to remove the "THE" and replace it with "TABLE" too. Good luck.

  • ConditionSortStep with measure based sorting

    Hi,
    i have problem with ConditionSortStep with measure based sorting.
    I use this code :
    Selection sel = query.findSelection(dimensionID);
    OlapQDR qdr = new OlapQDR(measureDim.getUniqueID());
    qdr.addDimMemberPair(dimTime.getUniqueID(),"YR2004");
    qdr.addDimMemberPair(dimPartner.getUniqueID(),"PLUS");
    ConditionSortStep stepM = new ConditionSortStep(dimensionID, sel.getHierarchy(), ConditionSortStep.MEASURE,ConditionSortStep.DESCENDING, measure.getUniqueID(), qdr);
    SortSpec sortSpec = new SortSpec();
    stepM.setAction(Step.ADD);
    sortSpec.addConditionSortStep(stepM);
    sel.setSortSpec(sortSpec);
    query.applySelection(sel);
    Members are sorted by measure, but only descending not in hierarchical ordering. When i change hierarchy in ConditionSortStep to (String)null, I get same result.
    I mean, the specified hierarchy in ConditionSortStep is not used, but I dont know why. Any ideas?
    BIBeans 9.0.4 - JSP
    DB 9.2.0.5 + OlapB patch
    Thanks...
    maddox

    Hi David,
    Sorry for not providing proper information.
    This is my Star Schema. Dim_cutomer, Dim_problem, Dim_geo, Fact_ticket.
    Dim_cutomer: Contians information about the Cutomer, account, Install Date, Install flag
    Dim_problem: Problem type, Problem group
    Dim_Geo: is Geographical dimension. like Division, Region ...
    Fact_ticket: Has the information about the each ticket.
    The requirement is to create a report based on division, region : 1. count # of Open ticket 2. Count # of closed ticket 3. % of Failure
    I am able to do count of Open and Close. but for % failure which is tricky and complecated. To calculate the % of failure
    Failure = Count of (FAI tickets) / Count of Installs.
    to count fai: there is flag in fact i can count the FAI, Installs : count of install falg which is in Dim_customer, i can count it in report. The problem is this report have prompts like Type of account, type of problem.
    As per the client, when i change the value of problem type the count of Installs should not changed & when i change the value of Type of Account value of Installs should change based on type of account. I dont no how to control this.
    As all the dim are joined with fact.
    It will be great help if some one give some hit or help...
    thanks in adavance
    Regards
    @li

  • Problem with a string method

    Hello, I am working on a program that converts Roman numerals to Arabic numbers and the opposite. I have the Arabic to Roman part down, yet Roman to Arabic part is causing troubles for me.
    I know that there are many solutions out there, yet I would like just solutions within my code that would fix the problem it has.
    Instead of the whole code, here's the method that changes Roman to Arabic.
         //method to convert Roman numerals to Arabic numbers
         public static int toArabic (String x)
              int arabica=0;
              char chars;
              for (int y=0; y<=(x.length()-1); y++)
                   chars=x.charAt(y);
                   switch (chars)
                        case 'C':
                             if( x.length() == 1)
                                  arabica+=100;
                                  y++;
                             else if (x.charAt(y+1)=='M')
                                  arabica+=900;
                                  y++;
                             else if (x.charAt(y+1)=='D')
                                  arabica+=400;
                                  y++;
                             else
                                  arabica+=100;
                             break;
                        case 'X':
                             if(x.length() == 1)
                                  arabica+=10;
                                  y++;
                             else if (x.charAt(y+1)=='C')
                                  arabica+=90;
                                  y++;
                             else if (x.charAt(y+1)=='L')
                                  arabica+=40;
                                  y++;
                             else
                                  arabica+=10;
                             break;
                        case 'I':
                             if(x.length() == 1)
                                  arabica+=1;
                                  y++;
                             else if (x.charAt(y+1)=='X')
                                  arabica+=9;
                                  y++;
                             else if (x.charAt(y+1)=='V')
                                  arabica+=4;
                                  y++;
                             else
                                  arabica++;
                             break;
                        case 'M':
                             arabica+=1000;
                             break;
                        case 'D':
                             arabica+=500;
                             break;
                        case 'L':
                             arabica+=50;
                             break;
                        case 'V':
                             arabica+=5;
                             break;
    There's a problem with this, however, is that whenever I put something in like XX, CC, XXX, or II, the program says
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
    at java.lang.String.charAt(String.java:687)
    at RomanNumerals.toArabic(RomanNumerals.java:172)
    at RomanNumerals.main(RomanNumerals.java:33)
    I think this problem is caused by the if-else and else-if statements in my method for cases C, X, and I, as this problem doesn't come up when I do similar things to cases without the if statements. Could you perhaps find out what is causing this problem? I've been working on it for days after finishing the rest and I can't figure it out.
    Thanks

    import java.io.*;
    public class RomanNumerals{
              public static void main (String [] args)
              DataInput keyboard=new DataInputStream (System.in);
              String input;
              try
                   //options
                   System.out.println("1. Roman numerals to Arabic numbers");
                   System.out.println("2. Arabic numbers to Roman numerals");
                   System.out.println("3. Exit");
                   System.out.print("Enter your option: ");
                   input=keyboard.readLine();
                   int choice=Integer.parseInt(input);
                   switch (choice)
                        //Roman numerals to Arabic numbers
                        case 1:
                             String romanInput, ro;
                             int answer1;
                             System.out.print("Enter a Roman numeral: ");
                             romanInput=keyboard.readLine();
                             ro=romanInput.toUpperCase();
                             answer1=toArabic(ro); //line 33 where the error occurs
                             System.out.println("The Arabic number is: "+answer1);
                             break;
                        //Arabic numbers to Roman numerals
                        case 2:
                             String arabicInput, answer;
                             System.out.print("Enter an Arabic number: ");
                             arabicInput=keyboard.readLine();
                             int arabic=Integer.parseInt(arabicInput);
                             answer=toRomans(arabic);
                             System.out.println("The Roman numeral is: "+answer);
                             break;
                        case 3:
                             break;
                        default:
                             System.out.println("Invalid option.");
              catch(IOException e)
                   System.out.println("Error");
                   //method to convert Arabic numbers to Roman numerals
         public static String toRomans (int N)
              String roman="";
              while (N>=1000)
                   roman+="M";
                   N-=1000;
              while (N>=900)
                   roman+="CM";
                   N-=900;
              while (N>=500)
                   roman+="D";
                   N-=500;
              while (N>=400)
                   roman+="CD";
                   N-=400;
              while (N>=100)
                   roman+="C";
                   N-=100;
              while (N>=90)
                   roman+="XC";
                   N-=90;
              while (N>=50)
                   roman+="L";
                   N-=50;
              while (N>=40)
                   roman+="XL";
                   N-=40;
              while (N>=10)
                   roman+="X";
                   N-=10;
              while (N>=9)
                   roman+="IX";
                   N-=9;
              while (N>=5)
                   roman+="V";
                   N-=5;
              while (N>=4)
                   roman+="IV";
                   N-=4;
              while (N>=1)
                   roman+="I";
                   N-=1;
              return(roman);
         //method to convert Roman numerals to Arabic numbers
         public static int toArabic (String x)
              int arabica=0;
              char chars;
              for (int y=0; y<=(x.length()-1); y++)
                   chars=x.charAt(y);
                   switch (chars)
                        case 'C':
                             if( x.length() == 1)
                                  arabica+=100;
                                  y++;
                             else if (x.charAt(y+1)=='M')
                                  arabica+=900;
                                  y++;
                             else if (x.charAt(y+1)=='D')
                                  arabica+=400;
                                  y++;
                             else
                                  arabica+=100;
                             break;
                        case 'X':
                             if(x.length() == 1)
                                  arabica+=10;
                                  y++;
                             else if (x.charAt(y+1)=='C')   //the line 172 where error occurs
                                  arabica+=90;
                                  y++;
                             else if (x.charAt(y+1)=='L')
                                  arabica+=40;
                                  y++;
                             else
                                  arabica+=10;
                             break;
                        case 'I':
                             if(x.length() == 1)
                                  arabica+=1;
                                  y++;
                             else if (x.charAt(y+1)=='X')
                                  arabica+=9;
                                  y++;
                             else if (x.charAt(y+1)=='V')
                                  arabica+=4;
                                  y++;
                             else
                                  arabica++;
                             break;
                        case 'M':
                             arabica+=1000;
                             break;
                        case 'D':
                             arabica+=500;
                             break;
                        case 'L':
                             arabica+=50;
                             break;
                        case 'V':
                             arabica+=5;
                             break;
              return(arabica);
         }When I put in XX as the input, this is what the error comes out as:
    Enter a Roman numeral: XX
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
        at java.lang.String.charAt(String.java:687)
        at RomanNumerals.toArabic(RomanNumerals.java:172)
        at RomanNumerals.main(RomanNumerals.java:33)

  • Can i format numbers with spry?

    Can i format numbers for display with spry? I've got a number
    field and want to put commas in for thousand seperators and also
    need to pad some numbers with zeros....kinda like numberformat()
    really in CF, else i guess I have to do it with in my data
    preparation,
    thanks,
    john.

    Hi John,
    So if I were going to make this work with your XML, I would
    create a custom column on the fly after the data was loaded. This
    custom column would strip the formatting and convert the resulting
    numbers into real numbers. Also, for any rows that had nothing, it
    would stick a zero in this custom column.
    Then when it comes time for sorting, you sort on the custom
    column instead of the formatted one.
    Look at this example. It shows you how you can create custom
    columns:
    http://labs.adobe.com/technologies/spry/samples/data_region/CustomColumnsSample.html
    --== Kin ==--

  • Calculate numbers with digits

    Hi all,
    Can someone tell me how to calculate numbers with digits.
    Let me explain first. The price comes in a xml format like: <price>2,90</price> (comma instead of dot)
    var price:String = XML(dgProducts.selectedItem).child("price").toString();
    total += Number(price); --> this won't work, if I use 2.90 there is no problem.
    So, how can I fix this?
    Hans

    Try using NumberBase's formatDecimal property to first convert it to "." separated and then using parseNumberString method of it to extract Number.
    then do calculation and finally you can convert to comma separated again.
    Formatted Object always returns a string .
    check this ref link.
    http://livedocs.adobe.com/flex/3/langref/mx/formatters/NumberBase.html
    mark post accordingly if it helps.
    Cheers,
    Prad.

  • 6500 syncs contact names but not numbers with Outl...

    I can get my 6500 slide to connect with my computer and it synchonises all my contacts with MS Outlook and if I add any new contacts that week it will sync them across aswell, but it only brings across the contact name not their phone number???
    This is rather annoying as I have 471 contacts on my Nokia 6500 slide. I cannot get the contacts to mass send via bluetooth either, so I was wondering if there is some sort of option I can tick to get all of my contacts details i.e. numbers, home numbers and email address.
    Any help would be greatly appreciated.
    Regards,
    James

    Does anyone have an answer to this issue? I have been told to sit and bluetooth 1 by 1 but that will take me a long long time. Why doesn't the 6500 slide synch names AND numbers with outlook? Surely someone has a workaround here?
    Please please help. I have been carrying around 2 phones for the last few weeks now.
    Many thanks in advance.
    Regards,
    James

  • I have an iphone4 and my husband merge his numbers with mine and i think it was deleted can you tell me how can he get his number back on his phone

    have an iphone4 and my husband merge his numbers with mine and i think it was deleted can you tell me how can he get his number back on his phone

    Do you possibly mean the contacts have been merged?
    If so, where are each of you syncing contacts?  A supported application on the computer? iCloud or another cloud service? An Exchange server?
    WIthout details, it's difficult to offer specific resolutions.

  • SharePoint 2013 List View with query string filter stops working after editing view from browser

    I have created one list definition in which I have added one list view which will filter data from query string paramater
    So when I am creating list from my list definition, view with query string filter is working fine.
    But when I am modifying view from UI(I am not changing any thing , just opening "Modify View" page and then click on "Save" button), view gets stop working means it's not filtering data based on query string
    Any suggestion what I am missing?
    Below is my list view schema
    <View BaseViewID="11" Type="HTML" TabularView="FALSE" WebPartZoneID="Main" DisplayName="$Resources:OIPLBScoreCard,viewFilterTasksByTarget;" MobileView="True" MobileDefaultView="False" Url="FilteredTasks.aspx" SetupPath="pages\viewpage.aspx" DefaultView="FALSE" ImageUrl="/_layouts/15/images/issuelst.png?rev=23">
    <Toolbar Type="Standard" />
    <ParameterBindings>
    <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
    <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
    <ParameterBinding Name="TargetId" Location="QueryString(TargetId)" />
    </ParameterBindings>
    <JSLink>hierarchytaskslist.js</JSLink>
    <XslLink Default="TRUE">main.xsl</XslLink>
    <JSLink>clienttemplates.js</JSLink>
    <RowLimit Paged="TRUE">100</RowLimit>
    <ViewFields>
    <FieldRef Name="Body"></FieldRef>
    <FieldRef Name="Title"></FieldRef>
    <FieldRef Name="StartDate"></FieldRef>
    <FieldRef Name="DueDate"></FieldRef>
    </ViewFields>
    <ViewData>
    <FieldRef Name="PercentComplete" Type="StrikeThroughPercentComplete"></FieldRef>
    <FieldRef Name="DueDate" Type="TimelineDueDate"></FieldRef>
    </ViewData>
    <Query>
    <Where>
    <Eq>
    <FieldRef Name="oipscTargetLookup" LookupId="TRUE"/>
    <Value Type="Lookup">{TargetId}</Value>
    </Eq>
    </Where>
    </Query>
    </View>
    I have one lookup field from "Target List" in my source list and I want to filter data based on that lookup field.

    Hi JayJT,
    The Miscellaneous is located in the contact list that you used for the connection.
    So , you need to edit the page, then edit the contact list that you used, in the web part properties of the contact list, you will find Miscellaneous, then expand it and select ‘Server Render’ .
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How to replace numbers with text in tax return pdf using Adobe Acrobat X Pro

    How do I replace numbers with text in tax return pdf using Adobe Acrobat X Pro? The tax return was created using CCH software. Thanks for your review.

    Thanks Bill for your quick reply. CCH software is one of the major
    suppliers of tax return software. I found an internal source that helped me
    make the changes from numbers to text i.e. "$123,456" to "See Schedule O".
    I am not sure if I am working in form or final text. Thanks again! Kelly

  • Sling mapping issue with Query String

    For a button component, URL behaves differently with query string. Please let me know the sling mapping example for query string.
    Button component behavior across env:-
    Working Scenario:-
    - In Author edit mode, URL pointing to "/content/<websitelink>"
    - In Author preview mode shows URL "<host>:<port>/content/<websitelink>.html"
    - In Publisher mode shows URL, "<host>:<port>/<websitelink>", we do not want "/content" before website link so it is fine.
    Failure Scenario with query string:-
    - In Author edit mode URL pointing to "/content/<websitelink>?username=han"
    - In Author preview mode with URL "<host>:<port>/content/<websitelink>?username=han"
    - In Publisher mode, <host>:<port>/content/<websitelink>?username=han - Here we see the content, which is not acceptable in our scenario.
    Please let me know the mapping changes when we have a URL with query string.

    1) I assume you configure as per the rules mentioned in http://sling.apache.org/site/mappings-for-resource-resolution.html --> 'Mapping Entry Specification' under /etc/map. Based on the configuration in /etc/map and the website that we publish, it translates and shows all the applicable combination in the Felix console http://<host>:<port>/system/console/jcrresolver.
    2) How does Adobe CQ 5.4 resolve the right mapping, if we have multiple map folder like below in /etc directory with the same website with different rules.
    etc/map --> http --> <website> with property sling:match, sling:internalRedirect
    etc/map.publish --> http --> <website> with property sling:match, sling:internalRedirect
    etc/map.publish-stag --> http --> <website> with property sling:match, sling:internalRedirect
    Kindly clarify.

  • How to replace a particular striing with another string in jtextpane

    how to get replace a particular string with another string of a jtextpane without taking the text in a variable using getText() method .

    Thanks for your answer,
    "relevant object" means for you datasources, transfer rules and transformations ?
    With the grouping option "Save for system copy" I can't take easily all datasources, and others objects
    Will I have to pick all object one by one ?
    What would be the adjustement in table RSLOGSYSMAP ? For the moment it's empty.
    Regards
    Guillaume P.

  • Searching for numbers in a string

    I am trying to filter passwords stored in a string variable and ensure that they contain at least a number and one capital letter.
    how do you search for numbers in a string and search if that string contains a character in uppercase?

    function checkString(username){
    var userfield = username;
    var valid = '0123456789ABCDEFGHIJKLMN�OPQRSTUVWXYZ'; // define valid characters
    if(!isValid(userfield.value,valid)){
    alert("Invalid user name format");
    userfield.value="";
    userfield.select();
         userfield.focus();
    }else{
    err = 0;
    userfield = userfield.value;
    function isValid(string,allowed) {
    for (var i=0; i< string.length; i++) {
    if (allowed.indexOf(string.charAt(i)) == -1)
    return false;
    return true;
    }

  • Have a problem in Numbers with entering data directly into a cell when a table reaches a certain size and special characters are used?

    I am creating a list of words with special characters in some of them. I get to a point where I cannot enter data directly into the cell. I have to use the data entry bar at the top in the toolbar. Any solutions available?
    This is the table I am creating...
    From row 25 on, I am only able to enter data into the cell through the toolbar at the top and not directly into the cell itself. I believe that this problem originates from the special characters I have inserted in the previous records because if I do not use special characters, then the spreadsheet acts flawlessly. Have there been issues in Numbers with data entry, the size of a table, and using special characters?

    I would try removing the rows with "special" characters one at a time to see which one is causing the problem

Maybe you are looking for

  • Blackberry Curve 9380 Problem running V7.1.0.714

    Hi I upgrade my blackberry from version 7.1.0.234 to 7.1.0.714 and now I cannot set my mobile network to 2G network with the old version has an option only 2G. Is there a way to make it stayed on 2G Only? Also I had a problem with my internet browser

  • ARTIST PROBLEM AGAIN~!

    OKay sry to bug you guys again but this 5th gen is really anoying me compared to my 2 previous ipods. When i first recevived my 5th gen i loaded the library on and for some reason when i went into "artists" all the songs just showed up and no artist!

  • Calling a html page deployed in weblogic server using RequestDispatcher

    Hi All, I want to call a HTML page from a java page using requestdispatcher. The whole application is deployed in Weblogic server.I have used the below syntax to call the page from any machine.. ServletContext sc = getServletContext();      RequestDi

  • VBA Save Default Options

    I'm using Smart View 11.1.2.2.310 (build 247) with HFM. I have a macro written to change various settings. I want these settings saved as the default settings. Does anyone know how to save these as the default settings using VBA?

  • NI SECURITY

    Hi, I use LabVIEW 8.2.1 DSC. I have included NI Security Invoke Login Dialog.vi in my application. (right click from the Block Diagram DSC MODULE>>Security>>NI Security Invoke Login Dialog) But when the Dialog pops up, if you use the 'X' to close the