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.
import java.util.Scanner;
public class Demo {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
System.out.println("First add some characters...");
char[] a = s.next().toCharArray();
System.out.println("Elements = ");
for (int i = 0; i < a.length; i++)
System.out.println(a[i]);
}
}
public class Demo {
public static void main (String args[]) {
int arr[] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
System.out.println("Length of initial array = " + arr.length);
int len = arr.length;
int newArray[] = new int[len*2];
System.arraycopy(arr, 0, newArray, 0, len);
System.out.println("Length of new array = "+newArray.length);
}
}
import java.util.LinkedHashSet;
import java.util.Random;
import java.util.Set;
public class Demo {
public static void main(final String[] args) throws Exception {
Random randNum = new Random();
Set<Integer>set = new LinkedHashSet<Integer>();
while (set.size() < 5) {
set.add(randNum.nextInt(5)+1);
}
System.out.println("Random numbers with no duplicates = "+set);
}
}
import java.time.LocalDate;
import java.time.temporal.IsoFields;
public class Demo {
public static void main(String[] args) {
long quarters =
IsoFields.QUARTER_YEARS.between(
LocalDate.of(2019, 3, 20),
LocalDate.of(2019, 10, 25));
System.out.println("Quarters between the two dates = " + quarters);
}
}
import java.time.Instant;
import java.time.temporal.ChronoUnit;
public class Demo {
public static void main(String[] args) {
long seconds = Instant.ofEpochSecond(0L).until(Instant.now(), ChronoUnit.SECONDS);
System.out.println("Seconds since the beginning of the Java epoch = "+seconds);
}
}