Java input


#1

Hey guys!

Let me start out by asking to please be patient… Only since a year ago have i been only tech savy. I’m taking a Java class and am slowly learning the ways of geekhood…

So whats my issue? I’m not sure how to get user inputs in the Atom editor… Again, i am coding in Java, and i have been using the script package, which “Runs code in Atom!” It has been successful up until now, when using the Scanner to prompt for user input, it only says what the print line prompts it to say in the console. In other words, i am not reaching any errors, just exclusively getting the output of .out parts of my code, not able to input, which is part of the whole point for most of my projects at this point. Heres an excample project of what I’m trying to do… (Which is fully functional in an IDE like jGRASP, or simply writing in Atom, running in the command prompt.):

import java.util.Scanner;
public class Plurals {

public static String input = “space”;

public static void main(String[] args) {

  while (! input.equals("quit")) {
     Scanner scan = new Scanner(System.in);
     System.out.println("Enter a noun: (or 'quit' to end)");
     input = scan.next();
     int length = input.length();
     int lastletternumber = length - 1;
     int secondtolastletternumber = length - 2;
     char lastletter  = input.charAt(lastletternumber);
     char secondtolastletter = input.charAt(secondtolastletternumber);
     String lasttwoletters = input.substring(secondtolastletternumber, length);
     System.out.print("Plural of " + input + " is ");
     if (
        (lastletter == 'o') ||
        (lastletter == 'y') ||
        (lastletter == 'x') ||
        (lastletter == 's') ||
        (lastletter == 'f') ||
        (lasttwoletters.equals("ch")) ||
        (lasttwoletters.equals("sh")) ||
        (lasttwoletters.equals("ss")) ||
        (lasttwoletters.equals("fe"))
        ) {
        if (lastletter == 'o') {//Start of O and [Vowel]O.
           System.out.print(input);
           if (
              (secondtolastletter == 'a') ||
              (secondtolastletter == 'e') ||
              (secondtolastletter == 'i') ||
              (secondtolastletter == 'o') ||
              (secondtolastletter == 'u')
              ) {
              System.out.print("s");
           } else {
              System.out.print("es");
           }
        }//End of O and [Vowel]O.
        if (lastletter == 'y') {//Start of Y and [Vowel]Y.
           if (
              (secondtolastletter == 'a') ||
              (secondtolastletter == 'e') ||
              (secondtolastletter == 'i') ||
              (secondtolastletter == 'o') ||
              (secondtolastletter == 'u')
              ) {
              System.out.print(input);
              System.out.print("s");
           } else {
              System.out.print(input.substring(0, lastletternumber));
              System.out.print("ies");
           }
        }//End of Y and [Vowel]Y.
        if (
           (lastletter == 's') ||
           (lastletter == 'x') ||
           (lasttwoletters.equals("ch")) ||
           (lasttwoletters.equals("sh")) ||
           (lasttwoletters.equals("ss"))) {//Start of s, x, ch, sh, ss
           System.out.print(input);
           System.out.print("es");
        }//End of s, x, ch, sh, ss
        if (
           (lastletter == 'f') ||
           (lasttwoletters.equals("fe"))
           ) {//Start of f, fe
           if (lastletter == 'f') {
              System.out.print(input.substring(0, lastletternumber));
              System.out.print("ves");
           } else {
              System.out.print(input.substring(0, secondtolastletternumber));
              System.out.print("ves");
           }
        }//End of f, fe
     } else {
        System.out.print(input);
        System.out.print('s');
     }
  System.out.println();
  System.out.println();
  }
  System.out.print("Bye.");

}
}

Thanks for the help guys! It is greatly appretiated.


#2

Since this is a pretty common question, I’ve created a new FAQ for it: