Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions untitled/src/ua/jet/MainClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package ua.jet;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;


public class MainClass {

public static String screenReader(String message){
try {
System.out.println(message);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
return bufferedReader.readLine();
}catch (Exception e){
return "Wrong value!!!!";
}
}

public static void factorial(Integer numeral){

BigInteger factorial=BigInteger.valueOf(1);
if (numeral>=0){
for (int i=1 ; i < numeral+1 ; i++) {
factorial=factorial.multiply(BigInteger.valueOf(i));
}
System.out.println("Factorial for number - "+numeral+" is equal to - "+factorial.toString());
} else if (numeral<0){
System.out.println("For this number can not be counted factorial");
}

}

public static void sequenceFibonachi(Integer numeral){
if (numeral>0) {
List<BigInteger> listFibonachi = new ArrayList<BigInteger>();
for (int i = 0; i < numeral; i++) {
if (i == 0||i==1) {
listFibonachi.add (BigInteger.valueOf(1));
}else {
listFibonachi.add(listFibonachi.get(i-2).add(listFibonachi.get(i - 1)));
}
}
for (BigInteger elementFibonachi:listFibonachi){
System.out.print(elementFibonachi.toString() + " ");
}
}else {
System.out.println("Wrong value!!!");
}
}

public static void numberWordConverter(Integer numeral){
List<String> wordsList = new ArrayList<String>(10);
wordsList.add("Zero");
wordsList.add("One");
wordsList.add("Two");
wordsList.add("Three");
wordsList.add("Four");
wordsList.add("Five");
wordsList.add("Six");
wordsList.add("Seven");
wordsList.add("Eight");
wordsList.add("Nine");

try{
System.out.println(wordsList.get(numeral));
}catch (Exception e){
System.out.println("This is not numeral. . . . ");
}

}

public static void main(String[] args){

try {
Integer numeralFromScreen = Integer.parseInt(screenReader("Choose :\n1.Factorial\n2.Sequence of Fibonachi\n3.Write a word for your numeral"));
switch (numeralFromScreen){
case 1: factorial(Integer.parseInt(screenReader("Enter number :")));
break;
case 2: sequenceFibonachi(Integer.parseInt(screenReader("How many numbers from sequence you want to see?")));
break;
case 3: numberWordConverter(Integer.parseInt(screenReader("Enter your numeral:")));
break;
default:
System.out.println("wrong value!!!");
}

}catch (Exception e){
System.out.println("Wrong value\n"+ e.toString());
}

}
}
11 changes: 11 additions & 0 deletions untitled/untitled.iml
Original file line number Diff line number Diff line change
@@ -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="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>