Results 1 to 4 of 4
  1. #1
    jdubya is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Trying to get a string from user input

    I trying to get this code to get user input instead of reading from a hardcoded array. I'm getting compile errors while trying to get user input. Where did I go wrong? Here's some of the code:
    Java Code:
    // BubbleSort Java
    // compile with:  javac BubbleSort.java
    // run with: java BubbleSort
    
    import java.util.Arrays;
    import java.io.*;
    import java.util.Scanner;
    
    public class BubbleSort {
        
      public static void main(String args[]) {
    	String name;
        int swapHolder;
        int sizeOfArray = 0; 
        int pass = 1; // 
        int[] myArray;  
            //**write to array from file -- one int per line**
    	TextIO.put("Enter the filename from which you would like to read from: ");
    	name = TextIO.getln();
    	BufferedReader br = new BufferedReader(new FileReader(name));
        int num;
        while ((line = br.readLine()) != null) {
           myArray[sizeOfArray] = num;
           sizeOfArray ++;   
        }
        br.close();
    The errors:
    BubbleSort.java:18: error: cannot find symbol
    TextIO.put("Enter the filename from which you would like to read from: ");
    ^
    symbol: variable TextIO
    location: class BubbleSort
    BubbleSort.java:19: error: cannot find symbol
    name = TextIO.getln();
    ^
    symbol: variable TextIO
    location: class BubbleSort
    BubbleSort.java:22: error: cannot find symbol
    while ((line = br.readLine()) != null) {
    ^
    symbol: variable line
    location: class BubbleSort
    3 errors
    Last edited by jdubya; 04-13-2014 at 05:43 AM. Reason: typo

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,025
    Rep Power
    6

    Default Re: Trying to get a string from user input

    You have a number of things wrong here.

    Where is TextIO coming from? If it's a third party class then you need to import it. Where is line defined? And if you fix those
    you will get a runtime error since you never allocated myArray. You only declared it.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    ocean39 is offline Member
    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Default Re: Trying to get a string from user input

    why dont you simply use
    [code language="java"]

    Scanner input = new Scanner(System.in);
    System.out.println("Enter a string");
    s = in.nextLine();
    [/code]

  4. #4
    jdubya is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Trying to get a string from user input

    Quote Originally Posted by ocean39 View Post
    why dont you simply use
    [code language="java"]

    Scanner input = new Scanner(System.in);
    System.out.println("Enter a string");
    s = in.nextLine();
    [/code]
    I believe that will work. Thanks.

Similar Threads

  1. User string input?
    By synister1337 in forum New To Java
    Replies: 10
    Last Post: 01-31-2012, 11:01 PM
  2. How do i delete a section of a user inputed string that i input
    By DevenGosalia514 in forum New To Java
    Replies: 8
    Last Post: 03-18-2011, 05:02 AM
  3. User Input
    By brmcdani in forum New To Java
    Replies: 2
    Last Post: 02-05-2010, 02:59 AM
  4. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-16-2010, 12:02 AM
  5. Prompting user input of a string.
    By apfroggy0408 in forum New To Java
    Replies: 3
    Last Post: 03-09-2008, 07:23 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
  •