[Show all top banners]

Replies to this thread:

What people are reading
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 Need hep with JAVA...Any IT experts...
SAVE! for ease of future access.
Posted on 02-10-10 2:26 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?        

professional  ta hoina,  tara eikdum  sikaru  ni hoina,    yeso  code padhdha  ra  problem  chain  eua character  matrai   return  bhayecha  bhanda  kheri  problem  yo  chain  line  ma  bahye   jasto   lagyo:

for (int i=0; i < plainText.length(); i++) {
        char decode = (char)(plainText.charAt(i) + newShift);


         char[] done = {decode};
        cipherText= new String(done);

yahan  new String  chain  pani  loop   ko  bhitra  parecha,  so it  creates a  new  string  object every  time
u  go  through the  loop,  storing  only  one   character that is  stored in  done.   therefore,   it returns   the last  character.
also,   String in java is  "fixed" in a sense  that u cannot append  i t,   so  once u  create a  string,  changing  somethign in  it  basically  means  u have to create a new string... which is  what  u seem to  be  doing,  but if  that is what  u are  trying  to do,   u   might  need  one   to do  something  on this  line:

cipherText = new String(null); // i am not sure if u need this,  since i  am not sure if String by default
        // gets set to null.
for (int i=0; i < plainText.length(); i++) {
        char decode = (char)(plainText.charAt(i) + newShift);


         char[] done = {decode};
        cipherText= new String(cipherText + done);

a + with a string  on either side will try  to perform  the concat,   i am not sure  hoewever  if the compiler can automatically cast the char array as  string. if not,  u  may not  need the aray at all, and  just  do:

cipherText= new String(cipherText + decode);

this  from what i remember  might  work.
this however, is  not the most efficient way, i think, since  u are creating a new string every time in the loop. a better  way  would  be to  use  StringBuilder / StringBuffer.

here is a java doc link to stringbuilder


so f u declare cipherText as  Stringbuilder ,  then u can  use  something on the lines of


to  build the  string,

then  return  it as :


since  u r  trying to return a String type  object.

don't  know  ur level of expertise,  but since  the  q is about  encryption,  i am  assuming u are familiar with  java  docs.
timilai java  doc  padhne  baani chaina/ aunna  bhane  let me know,   ali ali explain  garne   koshish  garumla.

solution  thyakkai chahin  k   huncha  bhanera chahin  bannu sakdina,   ahile  compile  garera  debug  garna   jhyau  lagi racha,  hopefully this helps somewhat.
Last edited: 10-Feb-10 02:29 AM

Posted on 02-10-10 3:53 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?        

Define "char[] done" outside the for loop. And add every character shift in it inside the loop as you have done.

Also do this "cipherText= new String(done);" or " cipherText = done.toString()" outside the for loop.

After that you will be good to go...


Please Log in! to be able to reply! If you don't have a login, please register here.



Within last 365 days
Recommended Popular Threads Controvertial Threads
What stocks to buy -- Any recommendation
TRUMP 2016!!! Here is why?
महानियिका प्रियंका कार्कीजीलाइ खुल्ला पत्र !
Returning to Nepal
❤️ चिक्नी चमेली ❤️
which stock to buy
ट्रंप २०२०
tesla stock OMG !!
Anyone renewed their passport through DC embassy lately?
❤️ सम्मर लभ ❤️
मलाई ब्रेड खायो कि सारै पाद आउछ..
I m offered a Job in Bank in Nepal, should i go back ?
Wedding Costs in Nepal ? Party, Band Baaja !!!!???
Dr. Fauci न टोक्नु न बोक्नु भएको छ ट्रुम्पलाई
हाकिमनी संग- आज सुक्रबार -३
ओपन challenge फर गनाउने (underwear)
I met her on Sajha ...
नेपाली समुदायको भारी समर्थन Iowa caucus मा Bernie Sanders लाई - PHOTOS
Funny jokes
Presidential rights to assassination rights?
भात भन्या भात हो!
महानियिका प्रियंका कार्कीजीलाइ खुल्ला पत्र !
TRUMP 2016!!! Here is why?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters