Пример #1
0
  public static void main(String[] args) throws IOException {
    Scanner scanner = new Scanner(new BufferedInputStream(System.in));

    while (scanner.hasNext()) {
      String str = scanner.next();
      if (str.equals("*")) break;
      if ((int) str.charAt(0) < 97) num(str);
      else abcd(str);
    }
  }
Пример #2
0
 public static void main(String[] args) {
   /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
   Scanner in = new Scanner(System.in);
   String input = "";
   int n = 1;
   String output = "";
   while (in.hasNextLine()) {
     if (in.hasNext()) {
       output += n + " " + in.nextLine() + "\n";
       n++;
     }
   }
   System.out.println(output);
 }
Пример #3
0
  public static void main(String[] args) throws FileNotFoundException, IOException {
    JOptionPane myWindow;
    myWindow = new JOptionPane();
    String fileName;
    fileName = myWindow.showInputDialog("Enter External Text File to Open;");
    Scanner scanner = new Scanner(new File(fileName));
    JTextArea outputOriginalFile = new JTextArea();
    outputOriginalFile.setText("The Original File was:\n");
    JTextArea outputTextArea = new JTextArea();
    while (scanner.hasNext()) {
      String fullName = scanner.nextLine();
      outputOriginalFile.append(fullName + "\n");
    }
    myWindow.showMessageDialog(
        null, outputOriginalFile, "Opened file....", myWindow.INFORMATION_MESSAGE);

    PrintWriter pw = new PrintWriter(new File("outputOfFile.txt"));
    String firstName, middleName, lastName;
    JTextArea outputTextArea1 = new JTextArea();
    outputTextArea1.setText("The Modified Text File is:\n");
    Scanner scanner2 = new Scanner(new File(fileName));
    while (scanner2.hasNext()) {
      String fullName = scanner2.nextLine();
      StringTokenizer st = new StringTokenizer(fullName, " ");
      firstName = st.nextToken();
      middleName = st.nextToken();
      lastName = st.nextToken();
      pw.println(lastName + ", " + firstName + " " + middleName.substring(0, 1) + ".");
      outputTextArea1.append(
          lastName + ", " + firstName + " " + middleName.substring(0, 1) + "." + "\n");
    }
    myWindow.showMessageDialog(null, outputTextArea1, "Results....", myWindow.INFORMATION_MESSAGE);

    scanner.close();
    scanner2.close();
    pw.close();
  }
  private String getFileWords(String s) {
    String output = "";
    try {
      // THIS CODE SEGMENT WILL NOT RUN IN AN APPLET THAT IS NOT "SIGNED"
      // By default applets cannot alter files on the hard drive of the user.
      // If the panel is opened in a regular application the save button should work.
      // This can be tested in HomeworkApplication.java through HomeworkRun.java only

      File inputFile = new File(s);
      Scanner inputScanner = new Scanner(inputFile);

      while (inputScanner.hasNext()) {
        output = output + inputScanner.nextLine() + "\n";
      }

      inputScanner.close();
      String numWords = getWords(output);
      return numWords;
    } catch (IOException e) {
      outputLabel.append(e + "");
    }

    return output;
  }