Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 11th, 2004, 12:44 PM
Jimmy Scythe Jimmy Scythe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Jimmy Scythe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
a console ROT13 program gone bad!!! please help

For starters, here's the entire source code:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.lang.String;
public class ROT13 {

/** Creates a new instance of ROT13 */
public ROT13() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {

int x;
char[] Alpha = {'a','b','c','d','e','f','g','h','i','j','k','l',' m','n','o','p','q','r','s','t','u','v','w','x','y' ,'z',' ','A','B','C','D','E','F','G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','V','W','X','Y ','Z'};
char[] Rev = {'z','y','x','w','v','u','t','s','r','q','p','o',' n','m','l','k','j','i','h','g','f','e','d','c','b' ,'a',' ','Z','Y','X','W','V','U','T','S','R','Q','P','O', 'N','M','L','K','J','I','H','G','F','E','D','C','B ','A'};
char[] temp;

BufferedReader KeyboardInput;

KeyboardInput = new BufferedReader(new InputStreamReader(System.in));

String NewLine= new String();

while(((NewLine = KeyboardInput.readLine())!=null)){

x=NewLine.length();
temp=new char[x];

NewLine.getChars(0,x,temp,0);

for(int i=0; i <=53;i++){

for(int check=0; check <=53;check++){

if(temp[i]==Alpha[check]){
temp[i]= Rev[check];
}




}


}
System.out.println(temp);
}
}
}
__________________________________________________ __________________________________________________ ____________

Yeah, I realize it's a really small project but it's still not working. The problem is that I get a java.lang.ArrayIndexOutOfBoundsException on line 51. I think it's because I can't compare strings with operators but I'm not familiar enough with the language to know what class or method to call as and argument for the the if() expression. I'm assuming there is something in either java.lang.String or java.util.Arrays but I haven't found anything yet. If someone with more experience in this language could speed this along I would be very grateful.

Jimmy Scythe

Reply With Quote
  #2  
Old May 11th, 2004, 09:45 PM
Logwad Logwad is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 17 Logwad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"if(temp[i]==Alpha[check]){"

should be "if(temp[i].equals(Alpha[check])){"

.equals() compares two strings.
.equalsIgnoreCase() compares two strings without considering the case.

I might be wrong with the capitalization of these, but you can always do a quick google search to find what they are supposed to be.

Reply With Quote
  #3  
Old May 12th, 2004, 12:37 AM
Jimmy Scythe Jimmy Scythe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Jimmy Scythe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanx for the answer but....

I tried that not long after I posted. the problem now is that temp[i] can't be dereferenced. temp[] and Alpha[] are character arrays BTW. I'm thinking that I'm going to have to convert both values to ints and store them in temporary variables. I don't like that solution since it's ugly as all hell. Of course if I was that worried about program size I would have just used half the alphabet in Alpha[] and Rev[]. I'm also thinking that since I'm going to have to convert anyway, I might as well just pitch Alpha[] and Rev[] and test to see if the value is < or > the integer value of 'm'. There has got to be an easier way to convert types and/or sort and re-arrange character arrays and strings. Thanx for the answer though, it was solid advice.


Jimmy Scythe

Reply With Quote
  #4  
Old May 12th, 2004, 11:58 AM
Jimmy Scythe Jimmy Scythe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Jimmy Scythe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I also just placed the temp[i] in a plain char variable and did likewise to Alpha[check]. Apparently, you can't dereference chars at all.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > a console ROT13 program gone bad!!! please help


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap