Advertisement
Spocoman

10. Multiply by 2

Aug 26th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MultiplyBy2 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         while (true) {
  8.             double number = Double.parseDouble(scanner.nextLine());
  9.             if (number >= 0) {
  10.                 System.out.printf("Result: %.2f\n", number * 2);
  11.             } else {
  12.                 System.out.println("Negative number!");
  13.                 break;
  14.             }
  15.         }
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement