-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadDeci.java
More file actions
118 lines (110 loc) · 3.02 KB
/
ReadDeci.java
File metadata and controls
118 lines (110 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package readdeci;
/**
*
* @author miryn
*/
public class ReadDeci {
public static double readNum() throws Exception
{
char asciiNum;
int digitNum;
int counter = 0;
double first = 0.0;
double second = 0.0;
double result;
boolean isNeg = false;
asciiNum = (char)System.in.read();
while (asciiNum != '.')
{
if ( asciiNum == '-')
{
isNeg = true;
asciiNum = (char)System.in.read();
}
digitNum = asciiNum - '0';
first = first * 10 + digitNum;
asciiNum = (char)System.in.read();
}
asciiNum = (char)System.in.read();
while(asciiNum != '\n')
{
digitNum = asciiNum - '0';
second = (second * 10 + digitNum);
asciiNum = (char)System.in.read();
counter++;
}
while(counter > 0)
{
second = second/10;
counter = counter - 1;
}
result = first + second;
if ( isNeg == true)
result = result * -1;
return result;
}
public static double doLog(int base, int outcome)
{
while (base != outcome)
{
}
}
public static double readLog() throws Exception
{
String Log = "log";
char asciiNum;
boolean haveResult;
int digitNum;
int counter = 0;
int base = 0;
int outcome = 0;
double result;
asciiNum = (char)System.in.read();
while (asciiNum != '_')
{
if (counter == 3 && Log.equals("log"))
haveResult = true;
else if (counter == 3 && !(Log.equals("log")))
{
haveResult = false;
}
else
{
asciiNum = (char)System.in.read();
counter++;
}
}
asciiNum = (char)System.in.read();
while ( asciiNum != '(')
{
digitNum = asciiNum - '0';
base = base * 10 + digitNum;
asciiNum = (char)System.in.read();
}
asciiNum = (char)System.in.read();
while ( asciiNum != ')')
{
digitNum = asciiNum - '0';
outcome = outcome*10 + digitNum;
asciiNum = (char)System.in.read();
}
}
public static void main(String[] args) {
// TODO code application logic here
double user = 0.0;
System.out.println("Please enter a number");
try{
user = readNum();
}
catch ( Exception e)
{
System.out.println("Keyboard error");
}
System.out.println(user);
}
}