Help with Creating a method that takes a string of arrays?

i just begin my intro to programming and im a little stuck we had to write a program yesterday and i managed fine then today we had to work with arrays and i dont know much about arrays so im hoping someone here can point me in the right direction. This is what he wants *"Create a method called "printReceipts" that takes a String array of names (first names only) and prints out a message to customers using their name and telling them what customer number they are. The method should work with an array of any size."*
Im not asking you to do it for me just i gues point out what methods i need to change thanks
package edu.nmhu.cs245;
public class Assignment1 {
     private String messagePrefix1 = "Hello ";
     private String messagePrefix2 = ", \n";
     public String[] getName() {
          String[] names = new String[] {"Lonny", "Gil", "Hosein"};
          return names;
     public String getCompleteMessage(String name, String message) {
          String completeMessage = messagePrefix1 + name + messagePrefix2 + message ;
          return completeMessage;
      * @param args
     public static void main(String[] args) {
          Assignment1 a = new Assignment1();
          String[] names = a.getName();
          for (int i = 0; i < names.length; i++) {
               String printReciepts = a.getCompleteMessage(names,"You are customer number#" +(i+1));
               System.out.println(printReciepts);
               System.out.println();

Focus! You should know what every single line of code is supposed to do! And they should all add up to a larger goal.
Don't just put in stuff that seems like it's part of a relevant example.
     public String[] getName() {
          String[] names = new String[] {"Lonny", "Gil", "Hosein","Sam"};
          return names;
     }Are you supposed to do it that way? Or did it come with the assignment? It's (probably) fine for a homework assignment, but it's hardcoded data, which in practice one normally doesn't do.
          String completeMessage = messagePrefix1 + names + messagePrefix2 + messageSuffix ;Why do this? You're supposed to produce a receipt per use, not for all users at one.
          for (int i = 0; i < names.length; i++) OK, good. You could have used a foreach loop but this is fine.
               String printReciepts = a.getCompleteMessage(names,"You are customer number#" +(i+1));What is "getCompleteMessage"?  You didn't define it.  Do you think that it is created implicitly because of the local String variable you created called "completeMessage"?  It doesn't.           String2 a = new String2();Don't call your class "String2".  It doesn't mean anything.  Name it after the assignment or something.           a.printReceipts(names);"names" isn't defined.  There's a local variable called "names" in the getNames method, but it doesn't exist when you call this and it's unavailable anyway.  You probably meant to do           a.printReceipts(a.getName());                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Help with creating a method within a class

    I need help creating another method within the same class.
    Here is part of my progam, and could anyone help me convert the switch statement into a seperate
    method within the same class?
    import javax.swing.JOptionPane;
    public class Yahtzee
         public static void main (String[] args)
              String numStr, playerStr, str, tobenamed;
              int num, times = 13, roll, x, y, maxRoll = 3, z = 0, t;
              int firstDie, secondDie, thirdDie, fourthDie, fifthDie, maxDie = 5, reroll;
              int rerolling = 0, categoryChoice, score, nextDie1, nextDie2, nextDie3, nextDie4;
              Die die1, die2, die3, die4, die5;
              do
              numStr = JOptionPane.showInputDialog ("Enter the number of player: ");
              num = Integer.parseInt(numStr);
              while (num < 1 || num > 6); //end of do loop
              String [] player = new String[num];
              // boolean //finsih later to make category choice only once.
              for (x = 0; x < num; x++)
                   playerStr = JOptionPane.showInputDialog ("Name of Player" + (x + 1) + " :");
                   player[x] = playerStr;  
              } //end of for loop
              die1 = new Die();
               die2 = new Die();
               die3 = new Die();
               die4 = new Die();
               die5 = new Die();
              int scoring [][] = new int [num][13];//scoring aray
              int[] numDie = new int[maxDie];
              String[][] usedCategory = new String [num][times];
              for (x=0; x < 13; x++)
                   for (y = 0; y < num; y++)
                      usedCategory[y][x] = " ";
              for (int choices = 0; choices < times; choices++)
                   //player turns for loop.
                   for (x = 0; x < num; x++)
                        //rolls the die;
                          for (y = 0; y < maxDie; y++)
                               numDie[y] =  die1.roll();
                     numStr = JOptionPane.showInputDialog (player[x] + "\n~~~~~~~~~~~~~~~~~~~~~~~"
                                                                            + "\nDie1: " + numDie[0]
                                                                                + "\nDie2: " + numDie[1]
                                                                                + "\nDie3: " + numDie[2]
                                                                                + "\nDie4: " + numDie[3]
                                                                                + "\nDie5: " + numDie[4]
                                                                                + "\nWhich dice do you want to reroll");
                    reroll = numStr.length();
                    if (reroll == 0)
                        t = maxRoll;
                   else{                                                      
                    //reroll
                         for(t = 0; t < maxRoll; t++ )
                             for (y = 0; y < reroll; y++)
                                    rerolling = numStr.charAt(y);
                                 //create another mwthod later.
                                    switch (rerolling)
                                         case '1':
                                              numDie[0] =  die1.roll();
                                              break;
                                         case '2':
                                              numDie[1] =  die1.roll();
                                              break;
                                         case '3':
                                              numDie[2] =  die1.roll();
                                              break;
                                         case '4':
                                              numDie[3] =  die1.roll();
                                              break;
                                         case '5':
                                              numDie[4] =  die1.roll();
                                              break;
                                         default:
                                         t = maxRoll;//to be changed
                                    } //end of switch class
                              }//end of reroll for loop
                                   JOptionPane.showMessegeDialog (player[x] + "\n~~~~~~~~~~~~~~~~~~~~~~~"
                                                                                      + "\nDie1: " + numDie[0]
                                                                                          + "\nDie2: " + numDie[1]
                                                                                          + "\nDie3: " + numDie[2]
                                                                                          + "\nDie4: " + numDie[3]
                                                                                          + "\nDie5: " + numDie[4]
                                                                                          + "\nWhich dice do you want to reroll"
                                               switch (rerolling)
                                         case '1':
                                              numDie[0] =  die1.roll();
                                              break;
                                         case '2':
                                              numDie[1] =  die1.roll();
                                              break;
                                         case '3':
                                              numDie[2] =  die1.roll();
                                              break;
                                         case '4':
                                              numDie[3] =  die1.roll();
                                              break;
                                         case '5':
                                              numDie[4] =  die1.roll();
                                              break;
                                         default:
                                         t = maxRoll; //not really anything yet, or is it?
                                    } //end of rerolling switch class
                                       //categorychoice = Integer.parseInt(category);
                              }//end of t for loop            
                   }//end of player for loop.

    samuraiexe wrote:
    well, i should have said it is a yahtzee program, and i ask the user what they want to reroll and whatever number they press, the switch will activate the case and the array that it will reroll.
    HOw would i pass it as an argument?You put it in the argument list. Modifying your original code a bit:
    public static void switchReroll (int[] dice, int position) {
         switch (position) {
         case '1':
                 dice[0] =  die1.roll()
                 break;
         case '2':
                 dice[1] =  die1.roll();
                 break;
         case '3':
                 dice[2] =  die1.roll();
                     break;
         case '4':
                 dice[3] =  die1.roll();
                 break;
         case '5':
                  dice[4] =  die1.roll();
                 break;
         default:
                 t = maxRoll;//to be changed
        } //end of switch
    }which you could then call as this:
    switchReroll(numDie, reroll);Note that your code still isn't done; the above won't compile. This is just an example of how you could pass the stuff as an argument (and note how the values have different names in the main method than in the switchReroll method -- this works, but also note that it's the same array of ints in both).
    By the way -- you really don't need a switch statement for this. You can do the same thing with a couple lines of code, which would lessen the advantage for a separate method. But I'd suggest continuing down this path, and then you could change the implementation of the method later.

  • Help with a store function that takes string array

    Hi All,
    I have a function that takes in two string arrays, status_array, and gender_array. You can see the partial code below. Somehow if the value for the string array is null, the code doesn't execute properly. It should return all employees, but instead it returns nothing. Any thoughts? THANKS.
    for iii in 1 .. status_array.count loop
    v_a_list := v_a_list || '''' || status_array(iii) || ''',';
    end loop;
    v_a_list := substr(v_a_list, 1, length(trim(v_a_list)) - 1);
    for iii in 1 .. gender_array.count loop
    v_b_list := v_b_list || '''' || gender_array(iii) || ''',';
    end loop;
    v_b_list := substr(v_b_list, 1, length(trim(v_b_list)) - 1);
    IF v_a_list IS NOT NULL and v_b_list IS NOT NULL THEN
    v_sql_stmt := 'select distinct full_name from t_employee where status in (' || v_a_list || ') and gender in (' || v_b_list || ')';
    ELSIF v_a_list IS NOT NULL and v_b_list IS NULL THEN
    v_sql_stmt := 'select distinct full_name from t_employee where status in (' || v_a_list || ') ';
    ELSIF v_a_list IS NULL and v_b_list is not null THEN
    v_sql_stmt := 'select distinct full_name from t_employee where gender in (' || v_b_list || ')';
    ELSE
    v_sql_stmt := 'select distinct full_name from t_employee';
    END IF;
    OPEN v_fullname_list FOR v_sql_stmt;
    RETURN v_fullname_list;

    I'd first recommend trying to avoid the dynamic sql.
    use an approach like
    [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425] or
    [http://stackoverflow.com/questions/1625649/oracle-parameters-with-in-statement/1655743#1655743] or [http://stackoverflow.com/questions/1715978/how-to-use-an-oracle-associative-array-in-a-sql-query]
    but if that isn't in scope, do a
    dbms_output.putline(v_a_list) ;
    dbms_output.putline(v_b_list) ;
    dbms_output.putline(v_sql_stmt) ;around and see what it emits

  • Help with creating a sort method

    I'm trying to create a method that sorts three numbers entered by the user in increasing order IE 1,2,3. I'm having trouble creating the method though, heres what I have
    import java.util.Scanner;
    public class LabFivePartOne {
         public static void main(String[] args){
              Scanner input = new Scanner(System.in);
              System.out.println("Enter a number");
              double num1 = input.nextDouble();
              System.out.println("Enter a number");
              double num2 = input.nextDouble();
              System.out.println("Enter a number");
              double num3 = input.nextDouble();
              int k = sort(num1, num2, num3);
              System.out.println(k);
              public static int sort(double num1, double num2, double num3){
                   int result;
                   if (num1 < num2 && num2 < num3)
                        result = ?;
                   else
                        result = ?;
                   return result;
    }I put ? marks after the result = because i'm not sure what to put there, thats what I'm having trouble with.

    try this:
    double [] dblArr = new double [3];
    for (int i = 0; i < 3; i++)
          System.out.println ("Please enter number " + i);
          dblArr = input.nextDouble ();
    for (int x = 0; x < 2; x++)
    for (int y = x+1; y < 3; y++)
    if (dblArr [x] > dblArr [y])
    String temp = dblArr [x];
    dblArr [x] = dblArr [y];
    dblArr [y] = temp;
    Edited by: tam826 on Oct 7, 2008 6:54 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help with creating a Quiz

    Hey i need help with creating a quiz with scoring and all.
    I need a helping hand so if you can get me started that
    would help a lot.
    Use the Question class to define a Quiz class. A
    quiz can be composed of up to 25 questions. Define the add method
    of the Quiz class to add a question to a quiz. Define the giveQuiz
    method of the Quiz class to present each question in turn to the user,
    accept an answer for each one, and keep track of the results. Define
    a class called QuizTime with a main method that populates a quiz,
    presents it, and prints the final results.
    // Question.java Author: Lewis/Loftus/Cocking
    // Represents a question (and its answer).
    public class Question implements Complexity
    private String question, answer;
    private int complexityLevel;
    // Sets up the question with a default complexity.
    public Question (String query, String result)
    question = query;
    answer = result;
    complexityLevel = 1;
    // Sets the complexity level for this question.
    public void setComplexity (int level)
    complexityLevel = level;
    // Returns the complexity level for this question.
    public int getComplexity()
    return complexityLevel;
    // Returns the question.
    public String getQuestion()
    return question;
    // Returns the answer to this question.
    public String getAnswer()
    return answer;
    // Returns true if the candidate answer matches the answer.
    public boolean answerCorrect (String candidateAnswer)
    return answer.equals(candidateAnswer);
    // Returns this question (and its answer) as a string.
    public String toString()
    return question + "\n" + answer;
    }

    Do you know why this lazy f&#97;rt-&#97;ss is back? Because when he posted his homework last week, some sorry-assed idiot went and did it for him.
    http://forum.java.sun.com/thread.jspa?threadID=5244564&messageID=10008358#10008358
    He didn't even thank the poster.
    It's the same problem over and over again. You feed the bears and it only teaches them to come back for handouts.
    My polite suggestion to the original poster: please do your own f&#117;cking homework.

  • Bind ADF table to EJB method that takes a argument (operation)

    Hi Oracles
    I can bind a ADF table to a EJB method that takes no arguments, and then JDeveloper calls the method a accessor. I would like to bind another ADF table to another EJB method that takes a argument, but there I have some problems. First of all JDeveloper will not allow this, can I work around that? Then obviously I have to pass the argument to this EJB method some how..?
    Do you guys have any way of fixing this? Is the only way to not bind the ADF table, and do it in code in the background, and how do I do this?
    Best regards
    Søren

    Thank you!
    I found it, and if I drag it to my JSP, it gives me these options:
    - Create Methods
    - ADF Link
    - ADF Button
    - ADF Menu Item
    - ADF Toolbar Button
    - ADF Image Link
    - Create Parameters
    - ADF Parameter Form
    I have one ADF table that is bound to a data control, and based on the selection on this table, I would like to show data in another table based on a EJB method that takes a id from the selected object from the first table. Either on the same JSP or on another JSP, whatever is easiests.
    Can you help me do this? Then I hope I learn something in the process :)
    Best regards
    Søren

  • Help with creating a form, I want to add a check box to enable me to unlock certain fields and deselect the block again

    Help with creating a form, I want to add a check box to enable me to unlock certain fields and deselect the block again

    Look to the right under "More Like This". Your issue has been discussed many many times. The error you are seeing is because you do not have enough free "contiguous" space on your hard drive. Read the other threads that address this issue to find how to solve the issue.
    Or, put "The disk cannot be partitioned because some files cannot be moved" into the search box at the upper right of this page.

  • Need Help with a getText method

    Gday all,
    I need help with a getText method, i need to extract text from a JTextField. Although this text then needs to converted to a double so that i can multiply a number that i have already specified. As you may of guessed that the text i need to extract already will be in a double format.e.g 0.1 or 0.0000004 etc
    Thanks for your help
    ps heres what i have already done its not very good though
    ToBeConverted.getText();
    ( need help here)
    double amount = (and here)
    total = (amount*.621371192);
    Converted.setText("= " + total);

    Double.parseDouble( textField.getText() );

  • Need help with creating a brush

    Hi guys,
    I wanted to ask for help with creating a brush (even a link to a tutorial will be goon enough ).
    I got this sample:
    I've created a brush from it, and i'm trying to get this kind of result:
    but it's only duplicates it and gives me this result:
    Can someone help me please understand what i need to define in order to make the brush behave like a continues brush instead of duplicate it?
    Thank you very much
    shlomit

    what you need to do is make a brush that looks like the tip of a brush. photoshop has several already but you can make your own that will be better.
    get a paintbrush and paint a spot kind of like what you did but dont paint a stroke. make it look kindof grungy. then make your brush from that, making sure to desaturate it and everything.
    EDIT:
    oh, and if you bring the fill down to like 10-20% your stroke will look better

  • I need help with creating PDF with Preview...

    Hello
    I need help with creating PDF documetns with Preview. Just a few days ago, I was able to create PDF files composed of scanned images (notes) and everything worked perfectly fine. However, today I was having trouble with it. I scanned my notebook and saved 8 images/pages in jpeg format. I did the usual routine with Preview (select all files>print>PDF>save as PDF>then save). Well this worked a few days ago, but when I tried it today, I was able to save it, but the after opening the PDF file that I have saved, only the first page was there. The other pages weren't included. I really don't see anything wrong with what I'm doing. I really need help. Any help would be greatly appreciated.

    I can't find it.  I went into advanced and then document processing but no batch sequence is there and everything is grayed out.
    EDIT: I realized that you cant do batch sequences in standard.  Any other ideas?

  • Help with creating an action - anto fit an image in a specific pixel size

    I am trying to create an action that takes the image in question and fits it with a specific pixel dimension. Some of the images are more horizontal in orientaion (like a school bus) and some are more on the vertical end (Like a tall building) They all need to be fit within a canvas size of 260 px x 196px. They need to keep the images original aspect ratio. Is there a way to do this with a single action, or do I need to create an action for vertical oriented images and one for horizontal orientated images?
    I hope that makes sense.
    Thanks,
    Dean

    Photoshop also ships with a plugin to do that. In CS5 Adobe added an option to it to not resize images if they fit.  If you do not use that option small images will be resize up in size like the image processor script.  There was a bug in that option I do not know if Adobe fixed that bug yet they may have.  If not it easy to fix if you know a little javascript. The plug-in was changed from a compiled plug-in in CS2 and earlier to a Photoshop Script in CS3 when Adpbe added plugin support into the Photoshop Scripting feature. The plugin has built in action support so you can use it in an action. When the Action is played back no dialog will be displayed the values use while recording the action were recorded into the action step by the plugin and will be used unless you make the action interactive by turning on the steps dialog. The image processor script is not a plug-in so it can not be automated.
    The plugin is menu File>Automate>Fit Image.......

  • I need help with creating some formulas

    I'm not sure if anyone around here can help me, but I'm trying to create a Numbers document and need some help with creating a formula/function.
    I have a column of amounts and I would like to create a formula which deducts a percentage (11.9%) and puts the result in another column.
    If anyone can help me, it would be greatly appreciated.

    Here is an example that shows one way to do this:
    The original data is in column A.  In column B we will store formulas to adjust the amounts:
    1) select the cell where you want to formula (in this case cell B2)
    2) Type the "=" (equal sign):
    3) click cell A2:
    4) now type the rest of the formula which is: "*(100-11.9)/100"  that is asterisk, then open parenthesis, 100 minus eleven point nine close parenthesis forward slash  one hundred
    The Asterisk is the multiply operator  (times) and the forward slash is the division operator (divide)
    now hit return.  select cell B2 and hover the cursor over the bottom edge of the cell:
    drag the little yellow dot down to "fill" the formula down as needed.

  • How to write a method that takes two arguments of same type

    Hi,
    I seldom do anything "advanced" in generics, but I've done my reading, and thought that I had an understanding of the basics, but I'm stuck on this. How do I write a method that takes two arguments that must be of exact same type.
    I've tried something like:
    public class GenericsTest1 {
        public static <T> void compare(T first, T second) {
    }But the compare method can in this case be called with e.g.
    String arg1 = null;
    Long arg2 = null;
    compare(arg1, arg2);I can restrict the call to something like GenericsTest1.<Long>compare(arg1, arg2), but I don't want to do it in the location that calls the method, and the method can still be invoked with subclasses of the specified type. E.g. this is valid (but I don't want it to be valid):
    Number arg1 = null;
    Long arg2 = null;
    GenericsTest1.<Number>compare(arg1, arg2);So I then changed the method into something like this:
    public class GenericsTest2 {
        public static <T, E extends T> void compare(T first, E second) {
    }It feels like I'm half way there now. Compare can't be called with e.g:
    Long arg1 = null;
    Number arg2 = null;
    compare(arg1, arg2);But this is still valid:
    Number arg1 = null;
    Long arg2 = null;
    compare(arg1, arg2);Hmm... So what to do? I only want the method to be callable when arg1 and arg2 is of exact same type. Everything else should give a compilation error.
    Kaj
    Ps. No, I don't have a need for this, I'm just curious.

    dannyyates wrote:
    I haven't gone through everything you've written, but I would expect that in the first instance, it's inferred <T> to be Object. This is a good reason to parameterise the class rather than the method wherever that makes sense.Thanks for you reply, but as I said this isn't related to anything that I'm going to use. I just want to know if it ca ben done with a static method and generics.
    Kaj

  • Plz help with a simple method

    hi all, i have to implement this method, that returns the string label of the given vertex in the graph . Valid numbers are 0 through numVerts(numberof vertices in graph) - 1;
    public string labedOf(int vertexNum){
    for (int i - 0; i !=adjlists.length; i++){ //adjlists is an array that holds the vertices
    if (i = vertexNum)
    break;}
    return adj;
    } // would this method work or there is something wrong with it, any kind of help is really appreciated.
    thanks a lot

    Hello,
    This method will not work, the comparison operator is not rigth as another user posted here. string should be String (capital!). The variable 'adj' isn't set anywhere.
    And if I understood you well you just want to return a String value of an element in the array passing the index as an argument. If this is the case there is not reason to loop through the whole array! It should be very short, something like:
    public String labelOf(int vertexNum){
    return adjlists[vertexNum];
    assuming adjlists is defined somewhere outside the method and holds the String's.
    Hope this helps,
    Hans.

  • I need help with Creating Key Pairs

    Hello,
    I need help with Creating Key Pairs, I generate key pais with aba provider, but the keys generated are not base 64.
    the class is :
    import java.io.*;
    import java.math.BigInteger;
    import java.security.*;
    import java.security.spec.*;
    import java.security.interfaces.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import au.net.aba.crypto.provider.ABAProvider;
    class CreateKeyPairs {
    private static KeyPair keyPair;
    private static KeyPairGenerator pairGenerator;
    private static PrivateKey privateKey;
    private static PublicKey publicKey;
    public static void main(String[] args) throws Exception {
    if (args.length != 2) {
    System.out.println("Usage: java CreateKeyParis public_key_file_name privete_key_file_name");
    return;
    createKeys();
    saveKey(args[0],publicKey);
    saveKey(args[1],privateKey);
    private static void createKeys() throws Exception {
    Security.addProvider(new ABAProvider());
    pairGenerator = KeyPairGenerator.getInstance("RSA","ABA");
    pairGenerator.initialize(1024, new SecureRandom());
    keyPair = pairGenerator.generateKeyPair();
    privateKey = keyPair.getPrivate();
    publicKey = keyPair.getPublic();
    private synchronized static void saveKey(String filename,PrivateKey key) throws Exception {
    ObjectOutputStream out= new ObjectOutputStream(new FileOutputStream(filename));
    out.writeObject(key);
    out.close();
    private synchronized static void saveKey(String filename,PublicKey key) throws Exception {
    ObjectOutputStream out= new ObjectOutputStream( new FileOutputStream(filename));
    out.writeObject(key);
    out.close();
    the public key is:
    �� sr com.sun.rsajca.JSA_RSAPublicKeyrC��� xr com.sun.rsajca.JS_PublicKey~5< ~��% L thePublicKeyt Lcom/sun/rsasign/p;xpsr com.sun.rsasign.anm����9�[ [ at [B[ bq ~ xr com.sun.rsasign.p��(!g�� L at Ljava/lang/String;[ bt [Ljava/lang/String;xr com.sun.rsasign.c�"dyU�|  xpt Javaur [Ljava.lang.String;��V��{G  xp   q ~ ur [B���T�  xp   ��ccR}o���[!#I����lo������
    ����^"`8�|���Z>������&
    d ����"B��
    ^5���a����jw9�����D���D�)�*3/h��7�|��I�d�$�4f�8_�|���yuq ~
    How i can generated the key pairs in base 64 or binary????
    Thanxs for help me
    Luis Navarro Nu�ez
    Santiago.
    Chile.
    South America.

    I don't use ABA but BouncyCastle
    this could help you :
    try
    java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    java.security.KeyPairGenerator kg = java.security.KeyPairGenerator.getInstance("RSA","BC");
    java.security.KeyPair kp = kg.generateKeyPair();
    java.security.Key pub = kp.getPublic();
    java.security.Key pri = kp.getPrivate();
    System.out.println("pub: " + pub);
    System.out.println("pri: " + pri);
    byte[] pub_e = pub.getEncoded();
    byte[] pri_e = pri.getEncoded();
    java.io.PrintWriter o;
    java.io.DataInputStream i;
    java.io.File f;
    o = new java.io.PrintWriter(new java.io.FileOutputStream("d:/pub64"));
    o.println(new sun.misc.BASE64Encoder().encode(pub_e));
    o.close();
    o = new java.io.PrintWriter(new java.io.FileOutputStream("d:/pri64"));
    o.println(new sun.misc.BASE64Encoder().encode(pri_e));
    o.close();
    java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("d:/pub64"));
    StringBuffer keyBase64 = new StringBuffer();
    String line = br.readLine ();
    while(line != null)
    keyBase64.append (line);
    line = br.readLine ();
    byte [] pubBytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());
    br = new java.io.BufferedReader(new java.io.FileReader("d:/pri64"));
    keyBase64 = new StringBuffer();
    line = br.readLine ();
    while(line != null)
    keyBase64.append (line);
    line = br.readLine ();
    byte [] priBytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());
    java.security.KeyFactory kf = java.security.KeyFactory.getInstance("RSA","BC");
    java.security.Key pubKey = kf.generatePublic(new java.security.spec.X509EncodedKeySpec(pubBytes));
    System.out.println("pub: " + pubKey);
    java.security.Key priKey = kf.generatePrivate(new java.security.spec.PKCS8EncodedKeySpec(priBytes));
    System.out.println("pri: " + priKey);
    catch(Exception e)
    e.printStackTrace ();
    }

Maybe you are looking for

  • Sharepoint 2010 webpart database connectivity.

    Im developing a web part that allows users to create help-desk tickets. I'm developing using Visual studio 2012. Ive created some text boxes and drop down lists. I want to link my drop down lists to a database where the user can choose names from the

  • Cant download the CDR files in either CSV or in PDF format

    I have a CUCM 7.1.3 and where under the CAR tool, if I try to view the CDR file in either CSV or in PDF format I get the display in the screen itself as a text file and do not get a option to download it. This happens in both the cases when it is sel

  • Build Path Invalid = No Error ...

    I'm typically not interested in complaining when there's no errors, however I've noticed that when I'm building exe's in projects, if I tell it to put the exe and associated files in a directory that is invalid (like in a removed flash or network dri

  • Problem with macbook pro trackpad

    The bottom right part of the trackpad feels really weak, when i push it down it goes really deep i really dont know how this happened. Can you help please.

  • Difficulty with converted jpegs

    Howdy All!! I shot a job in RAW using a Canon 30D and imported into the AP library. I renamed all images when importing to reflect the job name, but of course all retained their .crw extension. I am now having trouble opening them in any other progra