Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Class Numeric

class Example { 
   static void main(String[] args) { 
      //Example of a int datatype 
      int x = 5; 
		
      //Example of a long datatype 
      long y = 100L; 
		
      //Example of a floating point datatype 
      float a = 10.56f; 
		
      //Example of a double datatype 
      double b = 10.5e40; 
		
      //Example of a BigInteger datatype 
      BigInteger bi = 30g; 
		
      //Example of a BigDecimal datatype 
      BigDecimal bd = 3.5g; 
		
      println(x); 
      println(y); 
      println(a); 
      println(b); 
      println(bi); 
      println(bd); 
   } 
}

Creating Your First Hello World Program

class Example {
   static void main(String[] args) {
      // Using a simple println statement to print output to the console
      println('Hello World');
   }
}

Execute Groovy Online

/* Hello World in Groovy */
println("Hello world")

eeeee

def minmaxSearch2(A)
{
    max = 0
    min = 0
    
    j = 1
    
    while (j < (A.size()-1))
    {
        if (A[j] > A[max]) max = j 
        if (A[j] < A[min]) min = j 
        j++
    }
    
    return A[min] + " und " + A[max]
}

A = [1, 7, 234, 23, 44, 5, 88, 3]
println "Das Feld " + A + " hat unter und obere Grenze von " + minmaxSearch2(A) + "."

Exponent Calculation

def int powerOfN (int x, int n) {
    int result = 1;
    for (int i = 0; i < n; i++) {
    result = result * x;
    }
    return result;
}

int myCalculation = powerOfN (2, 3);
System.out.print(myCalculation);

groovy number literals

/* Hello World in Groovy */
println("Hello world")
def a = 0.3 - 0.2
def b = 0.2 - 0.1
println a == b

test time convertion

import java.time.format.DateTimeFormatter
import java.time.LocalDateTime

def convertStringToDateTime(strDate) {  
     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd[ HH:mm]");
    return LocalDateTime.parseBest(strDate, formatter)
}


println convertStringToDateTime("2017-01-01") 

Multiplication Tables

int [][] multiplication = new int [10][10];
int r;
int c;

for (r = 0; r < 10; r++) {
    for (c = 0; c < 10; c++) {
        multiplication [r] [c] = (r + 1) * (c + 1);
    }
}

for (r = 9; r >= 0; r--) {
    for (c = 9; c >= 0; c--) {
        System.out.print(multiplication [r] [c]);
        System.out.print("\t");
    }
    System.out.print("\n");
}

Execute Groovy Online

/* Hello World in Groovy */
println("Hello world")

iteration21

class GroovyTut {
 
// main is where execution starts
static void main(String[] args){
 
  // Print to the screen
  println("Hello World");
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.