- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogarithm.java
More file actions
Latest commit
35 lines (33 loc) · 773 Bytes
/
Copy pathLogarithm.java
File metadata and controls
35 lines (33 loc) · 773 Bytes
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
/**
* Chapter 5.9
*
* Using Operators and if-else statements.
**/
importjava.util.Scanner;
publicclassLogarithm
{
publicstaticvoidmain(String[] args)
{
System.out.println("Give a number to take the log of!");
Scannerin = newScanner(System.in);
/*
* hasNextDouble just checks if the user's input is a
* double and if not returns ONLY the next token
* because of .next() method
*/
if(!in.hasNextDouble())
{
Stringword = in.next();
System.err.println(word + " NaN");
return;
}
doublenum = in.nextDouble();
if(num > 0)
{
doublelog = Math.log(num);
System.out.println(log + " is the natural log of " + num);
}
else
System.err.println(num + " is not a positive number.");
}
}