Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is designed to count various characters from within a text file but for some reason it only spits out a 0 for each

This program is designed to count various characters from within a text file but for some reason it only spits out a 0 for each variable whenever I print it. What is wrong?

/ //Program: PP5_15.java // //Description: A program that imports a text file and counts the number of parenthesis(left and right), commas, periods, //exclamation points, question marks, and vowels. // //Author: Tanner Mitas //Creation Date: 10/28/17 //

import java.util.Scanner; import java.io.*;

public class PP5_15 { public static void main(String[] args) throws IOException { String character; int period, commas, exclamation, question, digits, lparen, rparen, vowels; period = 0; commas = 0; exclamation = 0; question = 0; digits = 0; lparen = 0; rparen = 0; vowels = 0; Scanner fileScan; fileScan = new Scanner(new File("Chp5.txt")); while (fileScan.hasNext()) { fileScan.useDelimiter(""); character = fileScan.next(); character = character.toUpperCase(); if(character.equals(".")) period++; else if (character.equals(",")) commas++; else if (character.equals("!")) exclamation++; else if (character.equals("?")) question++; else if (character.equals("0")) digits++; else if (character.equals("1")) digits++; else if (character.equals("2")) digits++; else if (character.equals("3")) digits++; else if (character.equals("4")) digits++; else if (character.equals("5")) digits++; else if (character.equals("6")) digits++; else if (character.equals("7")) digits++; else if (character.equals("8")) digits++; else if (character.equals("9")) digits++; else if (character.equals("(")) lparen++; else if (character.equals(")")) rparen++; else if (character.equals("A")) vowels++; else if (character.equals("E")) vowels++; else if (character.equals("I")) vowels++; else if (character.equals("O")) vowels++; else if (character.equals("U")) vowels++; } System.out.println(period); System.out.println(vowels); System.out.println(commas); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions

Question

=+3 In what ways can an MNE improve or change its approach to IHRM?

Answered: 1 week ago