mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-14 01:16:07 +08:00
@ -1,18 +1,13 @@
|
|||||||
import java.lang.StringBuilder;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public class HexaDecimalToBinary {
|
public class HexaDecimalToBinary {
|
||||||
|
|
||||||
private final int LONG_BITS = 8;
|
private final int LONG_BITS = 8;
|
||||||
|
|
||||||
public void convert(String numHex) {
|
public void convert(String numHex) {
|
||||||
//String a HexaDecimal:
|
// String a HexaDecimal:
|
||||||
int conHex = Integer.parseInt(numHex, 16);
|
int conHex = Integer.parseInt(numHex, 16);
|
||||||
//Hex a Binary:
|
// Hex a Binary:
|
||||||
String binary = Integer.toBinaryString(conHex);
|
String binary = Integer.toBinaryString(conHex);
|
||||||
//Presentation:
|
// Presentation:
|
||||||
System.out.println(numHex + " = " + completeDigits(binary));
|
System.out.println(numHex + " = " + completeDigits(binary));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +22,7 @@ public class HexaDecimalToBinary {
|
|||||||
|
|
||||||
//Testing Numbers:
|
//Testing Numbers:
|
||||||
String[] hexNums = {"1", "A1", "ef", "BA", "AA", "BB",
|
String[] hexNums = {"1", "A1", "ef", "BA", "AA", "BB",
|
||||||
"19", "01", "02", "03", "04"};
|
"19", "01", "02", "03", "04"};
|
||||||
HexaDecimalToBinary objConvert = new HexaDecimalToBinary();
|
HexaDecimalToBinary objConvert = new HexaDecimalToBinary();
|
||||||
|
|
||||||
for (String num : hexNums) {
|
for (String num : hexNums) {
|
||||||
|
@ -1,33 +1,32 @@
|
|||||||
import java.io.*;
|
import java.util.Scanner;
|
||||||
import java.util.*;
|
|
||||||
import java.text.*;
|
|
||||||
import java.math.*;
|
|
||||||
import java.util.regex.*;
|
|
||||||
|
|
||||||
public class RootPrecision {
|
public class RootPrecision {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//take input
|
// take input
|
||||||
Scanner scn = new Scanner(System.in);
|
Scanner scn = new Scanner(System.in);
|
||||||
|
|
||||||
int N = scn.nextInt(); //N is the input number
|
// N is the input number
|
||||||
int P = scn.nextInt(); //P is precision value for eg - P is 3 in 2.564 and 5 in 3.80870.
|
int N = scn.nextInt();
|
||||||
|
|
||||||
System.out.println(squareRoot(N, P));
|
// P is precision value for eg - P is 3 in 2.564 and 5 in 3.80870.
|
||||||
}
|
int P = scn.nextInt();
|
||||||
|
System.out.println(squareRoot(N, P));
|
||||||
public static double squareRoot(int N, int P) {
|
}
|
||||||
double rv = 0; //rv means return value
|
|
||||||
|
public static double squareRoot(int N, int P) {
|
||||||
|
// rv means return value
|
||||||
|
double rv;
|
||||||
|
|
||||||
double root = Math.pow(N, 0.5);
|
double root = Math.pow(N, 0.5);
|
||||||
|
|
||||||
//calculate precision to power of 10 and then multiply it with root value.
|
// calculate precision to power of 10 and then multiply it with root value.
|
||||||
int precision = (int) Math.pow(10, P);
|
int precision = (int) Math.pow(10, P);
|
||||||
root = root * precision;
|
root = root * precision;
|
||||||
/*typecast it into integer then divide by precision and again typecast into double
|
/*typecast it into integer then divide by precision and again typecast into double
|
||||||
so as to have decimal points upto P precision */
|
so as to have decimal points upto P precision */
|
||||||
|
|
||||||
rv = (int)root;
|
rv = (int) root;
|
||||||
return (double)rv/precision;
|
return rv / precision;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user