lab-03:
- Count letters class. Class to test and handle exceptions.
This commit is contained in:
parent
430e05d3d0
commit
4b8ebcf60c
3
lab-03/.idea/.gitignore
vendored
Normal file
3
lab-03/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
lab-03/.idea/misc.xml
Normal file
6
lab-03/.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
lab-03/.idea/modules.xml
Normal file
8
lab-03/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/lab-03.iml" filepath="$PROJECT_DIR$/lab-03.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
lab-03/.idea/vcs.xml
Normal file
6
lab-03/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
11
lab-03/lab-03.iml
Normal file
11
lab-03/lab-03.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
28
lab-03/src/CountLetters.java
Normal file
28
lab-03/src/CountLetters.java
Normal file
@ -0,0 +1,28 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CountLetters {
|
||||
public static void main(String args[]){
|
||||
int[] counts = new int[26];
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.print("Enter a single word (Letters only, please): ");
|
||||
String word = in.nextLine();
|
||||
word = word.toUpperCase();
|
||||
|
||||
int j = 0;
|
||||
try{
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
j++;
|
||||
counts[word.charAt(i)-'A']++;
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfBoundsException e){
|
||||
System.out.println("Found number: " + word.charAt(j-1) );
|
||||
}
|
||||
|
||||
for (int i = 0; i < counts.length; i++){
|
||||
if (counts[i] != 0)
|
||||
System.out.println((char)(i + 'A') + ": " + counts[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user