Smith Numbers in Java

Chandu yadav
Updated on 25-Jun-2020 12:19:59

1K+ Views

A composite number whose sum of digits equal to the sum of the digits of its prime factors.Ex: 58 = 2 x 29 (5 + 8 = 12) (2+ 2 + 9 = 12)Programpublic class SmithNumbers {    public static boolean isPrime(int number) {       int loop;       int prime = 1;       for(loop = 2; loop < number; loop++) {          if((number % loop) == 0) {             prime = 0;          }       }       if (prime ... Read More

Sort Array in Case-Sensitive Order in Java

Arjun Thakur
Updated on 25-Jun-2020 12:19:25

410 Views

An array can be sorted in case-sensitive order using the java.util.Arrays.sort() method. Only a single argument required in this case for this method i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String args[]) {       String[] arr = new String[] { "apple", "mango", "Banana", "Melon", "orange" };       System.out.print("The unsorted array is: ");       System.out.println(Arrays.toString(arr));       Arrays.sort(arr);       System.out.print("The sorted array in case-sensitive order is: ");       System.out.println(Arrays.toString(arr));    } ... Read More

K-th Prime Factor of a Given Number in Java

George John
Updated on 25-Jun-2020 12:18:39

389 Views

Following is the Java program which prints the kth prime factor of a number n, when k and n are given.Programimport java.util.Scanner; public class KthPrimeFactor {    public static void main(String args[]) {       int number, k, factor = 0;       Scanner sc = new Scanner(System.in);       System.out.println("Enter a number :");             number = sc.nextInt();       System.out.println("Enter the k value :");       k = sc.nextInt();       int temp = k-1;             for(int i = 2; i< number; ... Read More

Easiest Way to Transfer Files from Phone to PC

Shankar Bhatt
Updated on 25-Jun-2020 12:17:52

179 Views

This question occurs in our minds when we have to transfer files and all old methods start giving us enough troubles. The one way is to synchronize your phone with the USB cable, but you cannot carry the cable everywhere. You can transfer your data through email or other conventional methods, but again these tricks come with a lot of mess. However, you can get this done through some easy tools mentioned here:Push BulletYou can connect your phone and PC completely with the help of this tool, which also gives you a feeling that both your device and PC are ... Read More

Find Politeness of a Number in Java

Ankith Reddy
Updated on 25-Jun-2020 12:17:45

246 Views

The numbers which can be expressed as the sum of positive consecutive integers are known as polite numbers.Ex: 5 = 2+3The number of ways a number can be expressed as the sum of positive integers will be the Politeness of that number.Ex: 9 = 4+5 || 2+3+4AlgorithmGet the prime factors of a number.Get the powers of prime factors greater than 2.Add 1 to all of them.Multiply them, subtract 1 from the result.Programimport java.util.Scanner; public class PolitenessOfANumber {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a number");   ... Read More

Subtract Minutes from Current Time Using Calendar.add() Method in Java

Samual Sam
Updated on 25-Jun-2020 12:16:40

2K+ Views

Import the following package for Calendar class in Java.import java.util.Calendar;Firstly, create a Calendar object and display the current date and time.Calendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us decrement the minutes using the calendar.add() method and Calendar.MINUTE constant. Set a negative value since you want to decrease the minutes.calendar.add(Calendar.MINUTE, -15);Example Live Demoimport java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar calendar = Calendar.getInstance();       System.out.println("Current Date = " + calendar.getTime());       // Subtract 15 minutes from current date       calendar.add(Calendar.MINUTE, -15); ... Read More

Compare Two Byte Arrays in a Single Line in Java

George John
Updated on 25-Jun-2020 12:16:20

181 Views

Two byte arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order. A program that compares two byte arrays using the Arrays.equals() method is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] argv) throws Exception {       boolean flag = Arrays.equals(new byte[] { 1, 7, 5 }, new byte[] { 1, 7, 5 });       System.out.println("The two byte arrays are ... Read More

Map Size Property in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 12:16:07

637 Views

The size property of Map object accepts a JSON string, and constructs an object based on the given text and, returns it.SyntaxIts Syntax is as followsmapVar.sizeExample Live Demo    JavaScript Example           var mapVar = new Map();       mapVar.set('1', 'Java');       mapVar.set('2', 'JavaFX');       mapVar.set('3', 'HBase');       mapVar.set('4', 'Neo4j');       document.write("Size of the map object: "+mapVar.size);     OutputSize of the map object: 4

Find All Divisors of a Natural Number in Java

Ankith Reddy
Updated on 25-Jun-2020 12:16:02

9K+ Views

Following is the Java program which prints all the divisors of a given number.Programimport java.util.Scanner; public class DivisorsOfNaturalNumber {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter required number :");       int num = sc.nextInt();             for(int i = 1; i

Computer Elapsed Time of an Operation in Milliseconds in Java

Chandu yadav
Updated on 25-Jun-2020 12:15:48

632 Views

To compute the elapsed time of an operation in milliseconds in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).Let us see a program to compute the elapsed time of an operation in milliseconds in Java −Example Live Demopublic class Example {    public static void main(String[] args) throws Exception {       // finding the time before the operation is executed       long ... Read More

Advertisements