Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2008, 03:56 AM
Member
 
Join Date: Apr 2008
Posts: 1
whiterex is on a distinguished road
need help with scanner
im currently writting a program with the aim of encoding a string.

"The program is to implement a simple encryption program. The user will be asked four questions:
• The String they wish to have encoded (which may contain spaces).
• The character you'd like used to seperate words in the output (to be stored in a char).
• The number of letters to shift each letter by (to be stored in an int variable).
• Whether or not punctuation is to be repeated in the output (to be stored in a boolean variable).
The answers to these questions will be used to encrypt the given uncoded string (once it has been capitalised), and the resulting coded string will be displayed on the screen."

so far i have managed to come up with this;
import java.util.Scanner;
Code:
public class AssigOne108 { public static void main(String[] args) { Scanner sc; String word, delimiter, punc; int shiftAmount, length, rightPos; char punc1, delim, text, letter; boolean pass; sc=new Scanner(System.in); { System.out.println("enter a word/phrase that you wish to encrypt"); word = sc.nextLine(); System.out.println("enter your desired delimiter"); delimiter = sc.nextLine(); delim = delimiter.charAt(0); System.out.println("enter the number of letters to shift the code"); shiftAmount = sc.nextInt(); System.out.println("would you like to include punctuation? true/false"); pass = sc.nextBoolean();} word = word.toUpperCase();} }
and i am unable to figure out how to change the ascii values of the letters in the string. im guessing i need to convert the string to a char???

Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-22-2008, 02:41 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
This is one of the things i miss about C++. Strings are just arrays of characters, but more advanced. Anyways, you've got it right. Just do a toCharArray, do your manipulation, then convert it back to a string. Nice and simple.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use Scanner with a number cew27 New To Java 8 01-29-2008 07:22 AM
MixedTypeInput example (Scanner) Java Tip Java Tips 0 01-18-2008 03:11 PM
Scanner class ajaymenon.k Advanced Java 1 11-26-2007 08:01 AM
Using ava.util.Scanner Java Tip Java Tips 0 11-20-2007 05:47 PM
help with IP scanner tommy New To Java 1 08-06-2007 09:00 PM


All times are GMT +3. The time now is 09:37 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org