Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: String + Scanner!

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post

    Smile String + Scanner!

    Okay, im using netbeans as my compiler. And don't judge me for my text. Im new and im just texting stuff. I can't get my Scanner to work with a String. last thing on the code, i got a School variable that i want to set to Good or Bad. And i want to use the (true/false if statement) But i keep getting errors. So, if anyone could just have a quick look at it, it would really help me
    Thx!

    package tester;
    import java.util.Scanner;
    public class Tester {
     
     
    public static void main(String args[]) {
        int age, sex;
        String School = "Good";
        Scanner scan = new Scanner(System.in);
     
     
                System.out.println("What's your sex?");
                System.out.println("[1] Male [2] Female");
                sex = scan.nextInt();
                System.out.println(sex == 1 ? "A guy huh." : "A woman huh.");
                System.out.println("What's your age?");
                age = scan.nextInt();
                System.out.println(age >= 23 ? "No school? Nice!" : "Still in school... That's boring");
                if (age <= 22){
                System.out.println("How is your school? Good or bad?");
                School = scan.nextString;
                System.out.println(School == Good ? "How nice" : "Aww, that's sad");
     
     
     
     
     
                }
     
     
        }
    }
    Last edited by Norm; December 5th, 2012 at 03:21 PM. Reason: Move question to this section


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: String + Scanner!

    i keep getting errors
    Please copy the full text of the error messages and paste them here so we can see what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: String + Scanner!

    all errors!


    School = scan.nextString;
    symbol: variable nextString
    location: variable scan of type Scanner

    System.out.println(School == Good ? "How nice" : "Aww, that's sad");
    symbol: variable Good
    location: class Tester
    2 errors
    The following error occurred while executing this line:
    Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

    --- Update ---

    If you don't know how to fix it, can you do it on another way? With the true and false statement? :/

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: String + Scanner!

    Where is the error message? What you've posted has left off the text of the error message.
    That's in the first line of the message.
    Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    Here "cannot find symbol" is the error.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: String + Scanner!

    But i can't copy those errors, do i have to write those down? :/

    --- Update ---

    Sry for spam, my internet went down and i pressed post some times :O

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: String + Scanner!

    Line 10: The assigned value is never used
    ----
    Line 23: Cannot find symbol
    symbol: variable nextString
    location: variable scan of type Scanner
    ----
    Line 24:
    Cannot find symbol
    Symbol: variable Good
    lovation: class Tester
    ----

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: String + Scanner!

    Line 10: The assigned value is never used
    ----
    Line 23: Cannot find symbol
    symbol: variable nextString
    location: variable scan of type Scanner
    ----
    Line 24:
    Cannot find symbol
    Symbol: variable Good
    lovation: class Tester
    ----

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: String + Scanner!

    Cannot find symbol
    symbol: variable nextString
    The compiler can not find a definition for nextString. You need to define ALL variables that are used in the program.
    Cannot find symbol
    Symbol: variable Good
    Same problem. Where is the variable: Good defined?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  2. Question about Scanner and String values
    By cecilg23 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 9th, 2012, 07:58 PM
  3. [SOLVED] difference between String Concatenation and String -Buffer/Builder .append(<value>)
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 3rd, 2011, 08:16 AM
  4. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM