Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- import java.util.Scanner;
- import java.util.regex.Pattern;
- public class App {
- public static void main(String[] args) {
- //printCustomTextFiveTimes("I like to write Java code!");
- //System.out.println(sumTwoIntegerNumbers(75, 15));
- //greetMeWithTheName();
- //multiplyTwoIntegerNumbers();
- //computeAdvancedFormula();
- double value = 1f/3f;
- System.out.printf("%.2f", value);
- System.out.println();
- System.out.printf("%.3f", value);
- }
- //1
- public static void printCustomTextFiveTimes(String yourText) {
- int initialValue = 0;
- while (initialValue < 5) {
- System.out.println(yourText);
- initialValue++;
- }
- }
- //2
- public static int sumTwoIntegerNumbers(int firstNumber, int secondNumber) {
- return firstNumber + secondNumber;
- }
- //3
- public static void greetMeWithTheName() {
- // https://www.geeksforgeeks.org/ways-to-read-input-from-console-in-java/
- Scanner in = new Scanner(System.in);
- System.out.print("Enter your name: ");
- String userName = in.nextLine();
- if (iSStringContainsDigits(userName)) {
- System.out.println("Your name contains digits. Please to change it :)");
- } else {
- System.out.println("Nice to meet you, " + userName + "!");
- }
- }
- //4
- public static void multiplyTwoIntegerNumbers() {
- Scanner in = new Scanner(System.in);
- System.out.print("Enter your first number: ");
- int firstNumber = in.nextInt();
- System.out.print("Enter your second number: ");
- int secondNumber = in.nextInt();
- System.out.println("Result: " + firstNumber * secondNumber);
- }
- //5
- public static void computeAdvancedFormula() {
- System.out.println(4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11)));
- }
- //
- public static boolean iSStringContainsDigits(String yourText) {
- return Pattern.compile("[0-9]").matcher(yourText).find();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement