+ 5

What is different between boolean and float? give one example of each

2nd Mar 2017, 2:35 AM
🎆Sourav Subhakant Dash🔥🔥
🎆Sourav Subhakant Dash🔥🔥 - avatar
4 Antworten
+ 8
basically boolean is true or false, float are single-precision decimal numbers (of course there are more details appart than that) You can see more information here: https://www.tutorialspoint.com/java/java_basic_datatypes.htm Hope it helps 😉
2nd Mar 2017, 2:49 AM
C.E.
C.E. - avatar
+ 3
yeah thanks any more examples
2nd Mar 2017, 2:50 AM
🎆Sourav Subhakant Dash🔥🔥
🎆Sourav Subhakant Dash🔥🔥 - avatar
+ 3
bool test = true; //boolean state (can only be true or false) double otherTest = 1.5; // floating point number (or number with decimal places)
2nd Mar 2017, 3:59 AM
seamiki
seamiki - avatar
+ 1
A bool variable can equal true or false. The float variable can equal decimal numbers and integers. I'm going to give an example of each using the programming language c++. An example of bool is: #include <iostream> using namespace std; int main(){ cout << "You had a good day (true or false)" << endl; bool goodDay; cin >> goodDay; if(goodDay == true) then { cout << "I am happy for you" << endl; } else { cout << "Aw, I hope you feel better soon" << endl; } return 0; } An example of float is: #include <iostream> using namespace std; int main(){ float num; cout << "What number do you want to divide by two?" << endl; cin >> num; num /= 2; cout << "The number you have given, divided by two, is " << num; return 0; } If num is set to 5, knce it is divided by 2, it will become 2.5. If the variable tyoe was integer instead, the 5 would become 2 ince divided by 2.
2nd Mar 2017, 3:50 AM
Rain
Rain - avatar