mladrad

Multiply By 2

Nov 25th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. package exc.ConditionalStatementsAdvanced.MoreExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MultiplyBy2 {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         double max = Integer.MAX_VALUE;
  10.  
  11.         for (int i = 0; i < max; i++) {
  12.             double num = Double.parseDouble(scan.nextLine());
  13.             if (num > 0) {
  14.                 num *= 2;
  15.                 System.out.printf("Result: %.2f%n", num);
  16.             } else {
  17.                 System.out.println("Negative number!");
  18.             }
  19.         }
  20.     }
  21. }
  22.  
Add Comment
Please, Sign In to add comment