SHARE
TWEET

Untitled

a guest Sep 21st, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.lang.Math;
  2. import java.util.Scanner;
  3. import java.util.regex.Pattern;
  4.  
  5. public class App {
  6.  
  7.     public static void main(String[] args) {
  8.         //printCustomTextFiveTimes("I like to write Java code!");
  9.         //System.out.println(sumTwoIntegerNumbers(75, 15));
  10.         //greetMeWithTheName();
  11.         //multiplyTwoIntegerNumbers();
  12.         //computeAdvancedFormula();
  13.  
  14.         double value = 1f/3f;
  15.         System.out.printf("%.2f", value);
  16.         System.out.println();
  17.         System.out.printf("%.3f", value);
  18.     }
  19.  
  20.     //1
  21.     public static void printCustomTextFiveTimes(String yourText) {
  22.         int initialValue = 0;
  23.         while (initialValue < 5) {
  24.             System.out.println(yourText);
  25.             initialValue++;
  26.         }
  27.     }
  28.  
  29.     //2
  30.     public static int sumTwoIntegerNumbers(int firstNumber, int secondNumber) {
  31.         return firstNumber + secondNumber;
  32.     }
  33.  
  34.     //3
  35.     public static void greetMeWithTheName() {
  36.         // https://www.geeksforgeeks.org/ways-to-read-input-from-console-in-java/
  37.         Scanner in = new Scanner(System.in);
  38.         System.out.print("Enter your name: ");
  39.         String userName = in.nextLine();
  40.         if (iSStringContainsDigits(userName)) {
  41.             System.out.println("Your name contains digits. Please to change it :)");
  42.         } else {
  43.             System.out.println("Nice to meet you, " + userName + "!");
  44.         }
  45.     }
  46.  
  47.     //4
  48.     public static void multiplyTwoIntegerNumbers() {
  49.         Scanner in = new Scanner(System.in);
  50.         System.out.print("Enter your first number: ");
  51.         int firstNumber = in.nextInt();
  52.         System.out.print("Enter your second number: ");
  53.         int secondNumber = in.nextInt();
  54.         System.out.println("Result: " + firstNumber * secondNumber);
  55.     }
  56.  
  57.     //5
  58.     public static void computeAdvancedFormula() {
  59.         System.out.println(4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11)));
  60.     }
  61.  
  62.     //
  63.  
  64.     public static boolean iSStringContainsDigits(String yourText) {
  65.         return Pattern.compile("[0-9]").matcher(yourText).find();
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top