Boolean data type only used for true and false, or in other word only use to say that statement is true or false.
In this program we take (boolean booleanType=false;) boblean data type for (booleanType) and equal this data type to false in next step i apply (if) statement,that if
(booleanType==false) is truse then output is (boolean example data type value :false) which is line 8th in below program.
To understand logical (if and else) operates see java logical operators section in this site.
source code
- class theboolean
- {
- public static void main(String[] args)
- {
- boolean booleanType=false;
- if(booleanType==false)
- {
- System.out.println("boolean example data type value :"+booleanType);
- }
- }
- }
This program tell you how to take user input using java programing.
you only have to do add two line in program one is[InputStreamReader ir=new InputStreamReader(System.in);] which tell the java compiler that user is providing input from keybord, and 2nd line is [BufferedReader br=new BufferedReader(ir);]
hear java program take the input of user as buffer or in other word take in buffer memory.
In both line 6 and 7 we make object of InputStreamReader and BufferedReader method which are pre defined in java compiler.
We have to make object of each method to instantiate in a program, or in other word
if you want to use method in java user define or pre define you must have to make object of that methat.
source code
- import java.io.*;
- class user_input_two_no_for_sum
- {
- public static void main(String[] args)throws IOException
- {
- InputStreamReader ir=new InputStreamReader(System.in);
- BufferedReader br=new BufferedReader(ir);
- int no1,no2,sum;
- System.out.println("Enter no1=");
- no1=Integer.parseInt(br.readLine());
- System.out.println("Enter no2=");
- no2=Integer.parseInt(br.readLine());
- sum=no1+no2;
- System.out.println("Total="+sum);
- }
- }
This java program is able to calculate result in decimal value,
you only have to change 8 line of previous program from(double A,B,C,D,total;) to ( Float A,B,C,D,total;).
In this program we take four input number from user -A, B, C, D.
hear A, B, C are added and divided by D,this is the hole detail of program.
source code
- import java.io.*;
- class sum_of_three_no_divide_by_fourth_no
- {
- public static void main(String[] args)throws IOException
- {
- InputStreamReader ir=new InputStreamReader(System.in);
- BufferedReader br=new BufferedReader(ir);
- Float A,B,C,D,total;
- System.out.println("Eter no1");
- A=Float.parseFloat(br.readLine());
- System.out.println("Eter no2");
- B=Float.parseFloat(br.readLine());
- System.out.println("Eter no3");
- C=Float.parseFloat(br.readLine());
- System.out.println("Eter no4");
- D=Float.parseFloat(br.readLine());
- total=(A+B+C)/D;
- System.out.println("Total="+total);
-
- }
- }
This java program is able to calculate result in decimal value, you only have to change 8 line of previous program from(int A,B,C,D,total;) to (double A,B,C,D,total;).
In this program we take four input number from user -A, B, C, D.
hear A, B, C are added and divided by D,this is the hole detail of program.
source code
- import java.io.*;
- class sum_of_three_no_divide_by_fourth_no
- {
- public static void main(String[] args)throws IOException
- {
- InputStreamReader ir=new InputStreamReader(System.in);
- BufferedReader br=new BufferedReader(ir);
- double A,B,C,D,total;
- System.out.println("Eter no1");
- A=Double.parseDouble(br.readLine());
- System.out.println("Eter no2");
- B=Double.parseDouble(br.readLine());
- System.out.println("Eter no3");
- C=Double.parseDouble(br.readLine());
- System.out.println("Eter no4");
- D=Double.parseDouble(br.readLine());
- total=(A+B+C)/D;
- System.out.println("Total="+total);
- }
- }