Results 1 to 11 of 11
  1. #1
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Help with separating a String to be converted to a Char

    Java Code:
    public void data(){
       Scanner kbd=new Scanner(System.in);
       Queue<Integer> data=new LinkedList<Integer>();
        char[] separated;
       System.out.println("Input: ");
       String input=kbd.nextInt();
        
       data.add(message);
    
    
      System.out.println("Input: "+data.peek());
      System.out.println("Size"+ data.size());
    }
    Java Code:
    Current output:
    Input: data
    Size: 1
    The output i want is
    Java Code:
    Input: data
    Size: 4

    Provide some examples for your comment

    Dont comment nonesense
    Last edited by AnnaPatricia; 08-16-2012 at 05:08 PM.

  2. #2
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: Help with separating a String to be converted to a Char

    Where is the variable message defined and initialized?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  3. #3
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with separating a String to be converted to a Char

    i dont know what you are talking about

    Teach me those things

  4. #4
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: Help with separating a String to be converted to a Char

    First, surround your code with [code][/code] tags so that it is easier for us to read and communicate about your code.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  5. #5
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with separating a String to be converted to a Char

    Done done done done!

  6. #6
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: Help with separating a String to be converted to a Char

    Okay, on line 8 of your code you reference a variable called message. Where did you declare and initialize this variable?

    A declaration of a variable looks like this:

    Java Code:
    Car myCar;
    An initialization of a variable that has already been declared looks like this:

    Java Code:
    myCar = new Car();
    The combination of a declaration and initialization of a variable on one line looks like this:

    Java Code:
    Car myCar = new Car()
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  7. #7
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with separating a String to be converted to a Char

    i dont get what you mean

    i have no idea how to do that sir !

  8. #8
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: Help with separating a String to be converted to a Char

    Quote Originally Posted by AnnaPatricia View Post
    i dont get what you mean

    i have no idea how to do that sir !
    Then I recommend that you read this link: Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  9. #9
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with separating a String to be converted to a Char

    Java Code:
    import java.io.*;
    import java.util.*;
    
    
    
    public class CaesarCypher
    {
    	Queue<String> data=new LinkedList<String>();
    	String plainText;
    	int key;
    	public  void Demo()throws Exception
    	{
    		Scanner kbd=new Scanner(System.in);
    
    		System.out.println(" Choose an active:  ");
    		System.out.println(" 1. Encrypt.");
    		System.out.println(" 2. Decrypt");
    		System.out.println(" 3. Exit.");
    		System.out.println("--------------");
    		try{
    		int choice;
    		System.out.println("Enter Choice:");
    		choice=kbd.nextInt();
    		//your switch case goes here
    		switch(choice){
    			case 1:
    				encrypt();
    				break;
    			case 2:
    			//	decrypt();
    				break;
    			case 3:
    				System.exit(0);
    				break;
    			default:
    				System.out.println("Invalid");
                     break;
    		}
    
    		//any other code if you have
    	}
    		catch(Exception e){
    		 e.printStackTrace(); //This will catch all and any exception and print it
    	}
    
    
    
    
    	}
    	public void StringMsg(){
    		Scanner kbd=new Scanner(System.in);
    		System.out.println("Input text: ");
    		plainText=kbd.nextLine();
    		System.out.println("Input key:");
    		key=kbd.nextInt();
    		char[] letters= plainText.toCharArray();
    	}
    	public void encrypt(){
    		StringMsg();
    		char c= plainText.charAt(0);
    		data.add(plainText);
    
    
    		System.out.println("Message: "+plainText );
    		System.out.println("Key: " +key);
    		System.out.println("Cipher message: ");
    
    
    
    	}
    
    	public void decrypt(){
    	}
    	public static void main(String []args)throws Exception{
    		CaesarCypher d=new CaesarCypher();
    		d.Demo();
    
    	}
    
    }

    This is the program that im doing.
    i need to encrypt and decrypt message using CircularArrayQueue

    but i guess i just need a queue

  10. #10
    AnnaPatricia is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Help with separating a String to be converted to a Char

    java.bmp

    This is the ouput that i want to do ^_^

  11. #11
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: Help with separating a String to be converted to a Char

    Please don't PM members of this forum with pleas to check your thread. A thread becomes bolded and is sent to the top of the forum upon a new post already.

    You still haven't explained where message is declared and initialized. If you have a specific question, please ask. If not, you probably aren't going to find much help here.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Replies: 2
    Last Post: 07-05-2012, 08:10 AM
  2. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 09:24 PM
  3. Char to Bit String
    By Krooger in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 02:26 AM
  4. char to string
    By kian_hong2000 in forum New To Java
    Replies: 2
    Last Post: 08-25-2008, 01:51 PM
  5. Replies: 4
    Last Post: 03-25-2008, 12:16 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
  •