Results 1 to 2 of 2
  1. #1
    whiterex is offline Member
    Join Date
    Apr 2008
    Rep Power

    Post 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;
    Java 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.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???


  2. #2
    Join Date
    Apr 2008
    Fort Wayne, Indiana
    Rep Power


    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.

Similar Threads

  1. how to use Scanner with a number
    By cew27 in forum New To Java
    Replies: 10
    Last Post: 04-03-2009, 06:23 PM
  2. MixedTypeInput example (Scanner)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 02:11 PM
  3. Scanner class
    By ajaymenon.k in forum Advanced Java
    Replies: 1
    Last Post: 11-26-2007, 07:01 AM
  4. Using ava.util.Scanner
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-20-2007, 04:47 PM
  5. help with IP scanner
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts