Learning Java: Part 12: Comparing Doubles and Using the JOptionPane

preview_player
Показать описание

In this tutorial I will be discussing how to compare doubles without producing errors, and how to get your users' input in a basic GUI form!

Thanks for watching!
Рекомендации по теме
Комментарии
Автор

love how you are slowing down on the word "Actually". :) Thank you for all your videos! you are awesome

CatDaddyOG
Автор

"We have 10 fingers! ...Congratulations." XD

raphaelmorgan
Автор

Easy solution to that is changing the if parenthesis to 
"number - 1.5 < && number +1.5 >= 3"

&& is the symbol for additional requirements in an if or while statement, adding that number + 1.5 must be 3 or more.

MayFaire
Автор

One problem with that, if you input any number smaller than 1.5, it will also read as correct.

SangoProductions
Автор

I would just stick to the If (number == 1.5) becuase of the smaller number issue right>?

sdkay
Автор

I found the comparison issue too before looking at the comments.  I did a quick google search and found this code to do it
int retval = Double.compare(number, 1.5);
  
  if (retval == 0)
  {
   //If the user inputs 1.5
   JOptionPane.showMessageDialog(null, "You are correct! " + number);
  
  }
  else
  {
   JOptionPane.showMessageDialog(null, "You are wrong! " + number);

gregmiller
Автор

i got problem "Description Resource Path Location Type The project was not built since its build path is incomplete. Cannot find the class file for java.io.ObjectInputStream. Fix the build path then try building this project Applets or Graphics Unknown Java Problem"

It's happen again just like the previous tutorial =(

Saufii
Автор

I am using java 7.x . I wrote the exact same as you, but i get an error:
Exception in thred "main" java.lang.error: Unresolved compilation problem:
Syntax error on token ", ", * expected

at JOptionPaneandDoubles.java:8

LaughingOrange
Автор

i still can't understand why you don't want to make it == 1.5 in 5:44
i now what your if means but what is the problem when we use number == 1.5

dahshan_
Автор

Math.abs(number-1.5) will convert any negative value from (number-1.5) to absolute ie in maths modulus of a number!
if value is negative it wil return +ve of it .. eg : for -2.33 it will return 2.33
if value is positive it will return +ve ..

nice one!! :) !! i jus explained it cuz i thought it was necessary..

atishshakya
Автор

Great tutorial but there is just one thing that confuses me, why did you parse into double
(Double.parseDouble) why did we need to write this ?

jzkonain
Автор

I have typed in everything, I believe, as in the video. It shows no errors, and yet when I run it, no box pops open. Any ideas?

noahhaverkamp
Автор

I did everything you did, else is apparently an error?

milzgaming
Автор

I think i'm gonna go have an excellent, awesome, fantastic, day.

srowkless
Автор

If you put any number less than 1.5 like 1 or 1.2, it will be ok so this calculation is incorrect
and thank you for your video and keep going :)

mstjava
Автор

the problem is that he simply asked the computer if whatever you entered minus 1.5 is less then 0.00001 and anything negative is less than that. so the you should change the code like it is described in the top comment. That way it checks the absolute value of the number - 1.5

hedgechasing
Автор

I have an issue
import javax.swing.JOptionPane;
I am getting an error message : conflicts with type defined in the same file?

shanebagel
Автор

I can't import javax.swing.JOptionPane

bmacmillan
Автор

oh if you put 1 in it will say correct as well lol so you would have to add a few lines in to make sure that number is not less than .0001 after subbing the 1.5

NCRGhost
Автор

If you enter 1 into this it comes back as "Correct" and shouldn't....what gives?

williesmith