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 2 of 2

Thread: Code doesn't recognize a period

  1. #1
    Junior Member
    Join Date
    Apr 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code doesn't recognize a period

    My code is having issues. It says it doesn't recognize the .? And I'm a beginner, so I'm not using any advanced methods yet.

    import java.util.Scanner;
    import javax.swing.JOptionPane;
    public class FoolishMortals {

    static Scanner sc = new Scanner(System.in);
    static String Greeting = "Hello, ", God = "My creation", Human = "Fellow Homo Sapiens", Devil = "Foolish Mortal", Period = ".";
    public static void main (String[] args) {

    String s;
    s = JOptionPane.showInputDialong
    ("Who do you want to talk to? 1 for God, 2 for a human, 3 for the Devil.");
    int x = Integer.parseInt(s);
    System.out.println(Greeting + x + Period);
    }
    }


    C:\Users\*****\Documents\JAVA>javac FoolishMortals.java
    FoolishMortals.java:10: error: cannot find symbol
    s = JOptionPane.showInputDialong
    ^
    symbol: method showInputDialong(String)
    location: class JOptionPane
    1 error


    Same with this code.

    import java.util.Scanner;
    public class Enums {
    static Scanner sc = new Scanner(System.in);
    public enum Woods {Oak, Spruce, Birch, Acacia, DarkOak, Jungle, Mangrove, Cherry, Crimson, Warped}
    public static void main(String[] args) {
    System.out.println("What wood do you perfer?");
    Woods wood = sc.nextWoods;
    System.out.println("The wood is " + wood);
    }
    }

    C:\Users\*****\Documents\JAVA>javac Enums.java
    Enums.java:7: error: cannot find symbol
    Woods wood = sc.nextWoods;
    ^
    symbol: variable nextWoods
    location: variable sc of type Scanner
    1 error

    --- Update ---

    I got it fixed. Turns out, the Copilot pre for Windows is great with code.
    Last edited by CryoPyro4853; April 7th, 2024 at 03:40 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2024
    Posts
    25
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Code doesn't recognize a period

    It seems like there are a couple of typos causing errors in your code.

    For the first issue, the method name should be `showInputDialog` instead of `showInputDialong` in the `JOptionPane` class. So, the corrected line would be:

    ```java
    s = JOptionPane.showInputDialog("Who do you want to talk to? 1 for God, 2 for a human, 3 for the Devil.");
    ```

    And for the second issue, you should use `next()` instead of `nextWoods` to read the input as a string from the scanner, and then convert it to the enum type. Here's the corrected line:

    ```java
    Woods wood = Woods.valueOf(sc.next());
    ```

    After applying these changes, your code should compile and run without errors. Let me know if you need further assistance!

    After applying these changes, your code should compile and run without errors. If you ever need help with Java assignment or programming homework, there are online platforms like programminghomeworkhelp.com that offer guidance and support.

Similar Threads

  1. Scanner doesn't recognize "y"
    By tamulherin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2022, 08:26 PM
  2. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  3. Code doesn't work
    By Nicken99 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2014, 04:24 AM
  4. Period
    By l0p3n in forum Java Theory & Questions
    Replies: 3
    Last Post: March 1st, 2014, 09:40 AM
  5. Replies: 7
    Last Post: May 8th, 2013, 02:33 PM