Boolean:
A Boolean value is one with two choices: true or false, yes or no, 1 or 0. In Java, there is
a variable type for Boolean values:
boolean user = true;
So instead of typing int or double or string, you just type boolean (with a lower case "b").
After the name of you variable, you can assign a value of either true or false. Notice
that the assignment operator is a single equals sign ( = ). If you want to check if a
variable "has a value of" something, you need two equal signs ( = =).
Try this simple code:
boolean user = true;
if ( user == true) {
System.out.println("it's true");
}
else {
System.out.println("it's false");
}
a variable type for Boolean values:
boolean user = true;
So instead of typing int or double or string, you just type boolean (with a lower case "b").
After the name of you variable, you can assign a value of either true or false. Notice
that the assignment operator is a single equals sign ( = ). If you want to check if a
variable "has a value of" something, you need two equal signs ( = =).
Try this simple code:
boolean user = true;
if ( user == true) {
System.out.println("it's true");
}
else {
System.out.println("it's false");
}
package javapractice;
ReplyDeleteimport java.util.Scanner;
public class JavaPractice {
public static void main(String[] args) {
int sum;
Scanner input=new Scanner (System.in);
sum=input.nextInt();
if(sum==100)
{
System.out.println("You have got 100 Taka");
}
else
{
System.out.println("You have no money");
}
}
}