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:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old March 25th, 2004, 05:40 PM
hesketh hesketh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 hesketh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
character at

I'm trying to write a program that will return the position that a character is in the alphabet, from a string entered by the user.

For example the user enters abc it would then print 123 below this. Or if they simply wrote z it would return the number 26.

My code however has an error, and i'm not quite sure whats going on, any help would be appreciated.
*the error occurs on the line "arrayinputted = new char[] alphapos.tochararray();".



Code:
import java.awt.*;

import java.applet.*;

import java.awt.event.*;

//A program to display the position in the alphabet of a character entered

publicclass lettercount extends Applet implements ActionListener

{ 

String alphabet[] = {"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[] arrayinputted;

String alphapos;

Label prompt;

TextField userinput;



publicvoid init()

{

setBackground(Color.blue);

prompt = new Label ("Please enter a character and the computer will tell you what position that character is in the alphabet");

userinput = new TextField(10);

add(prompt);

add(userinput);

userinput.addActionListener(this);

}

//Prints out the position of the character

publicvoid paint(Graphics g)

{

g.drawString("The letter(s) you entered are at " +alphapos+ " position in the alphabet", 20, 200);

}

//Finds out what position the character is at

publicvoid actionPerformed (ActionEvent e)

{

alphapos = userinput.getText();

arrayinputted = new char[alphapos.length()];

arrayinputted = newchar[] alphapos.tochararray();

repaint();

}

}



Reply With Quote
  #2  
Old March 25th, 2004, 06:43 PM
djminmin djminmin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 djminmin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
so u want to change a String to Char array, right?

String s = "abc";
char[] c = s.toCharArray();
//test:
for(int i=0;i<c.legth;i++)
System.out.println(c[i]);

-----------------------------------------
but u dun really need a char array tho...
String s = "abc";
for(int i=00;i<s.length;i++)
System.out.println(s.charAt(i));

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > character at


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 | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway