Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Java Exercises: Accepts two double variables and test the specified condition

Java Basic: Exercise-153 with Solution

Write a Java program that accepts two double variables and test if both strictly between 0 and 1 and false otherwise.

Sample Solution:

Java Code:

import java.util.Scanner;
public class Solution {
	public static void main(String[] args) {
		 Scanner in = new Scanner(System.in);
		 System.out.print("Input first number: ");
         double n1 = in.nextDouble();
         System.out.print("Input second number: ");
         double n2 = in.nextDouble();
		 System.out.println(n1 > 0 && n1 < 1 && n2 > 0 && n2 < 1);
	}
}

Sample Output:

(101 + 0) / 3)-> 33
(3.0e-6 * 10000000.1)-> 30.0000003
(true && true)-> true
(false && true)-> false
((false && false) || (true && true))-> true
(false || false) && (true && true)-> false

Flowchart:

Flowchart: Java exercises: Accepts two double variables and test the specified condition.

Java Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Java program that accepts four integer from the user and prints equal if all four are equal, and not equal otherwise.
Next: Write a Java program to print the contents of a two-dimensional Boolean array where t will represent true and f will represent false.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Java: Tips of the Day

How to sort an ArrayList?

Collections.sort(testList);
Collections.reverse(testList);

That will do what you want. Remember to import Collections though!

Ref: https://bit.ly/32urdSe