Home Answers Viewqa Java-Interview-Questions Program in Java decimal to binary

 
 


vaibhav
Program in Java decimal to binary
1 Answer(s)      5 years and a month ago
Posted in : Java Interview Questions

i need a java example to String Reverse. Can you also explain the Java decimal to binary with the help of an example?

View Answers

April 23, 2008 at 8:28 PM


Hi friend,

import java.io.*;
import java.io.IOException;

public class StringReverseExam{
public static void main(String[] args) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter something string!");
String sre = buff.readLine();
System.out.println(ReverseString.reverseIt(sre));
}
}
class ReverseString{
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--)
dest.append(source.charAt(i));
return dest.toString();
}
}

---------------------------------

import java.io.*;
import java.util.*;

public class Concatenation {
private final long start;

public Concatenation(){
start = System.currentTimeMillis();
}
public long getElapsed(){
return System.currentTimeMillis() - start;
}
}

public class StringConcatention{
static final int n = 47500;

public static void main(String args[]){
// build up string using +
Concatenation con = new Concatenation();
String str1 = "";
for (int i = 1; i <= n; i++) {
str1 = str1 + "*";
}
System.out.println("elapsed time #1 = " + con.getelapsed());
// build up string using stringbuffer
con = new Concatenation();
stringbuffer sb = new stringbuffer();
for(int i = 1; i <= n; i++){
sb.append("*");
}
String str2 = sb.tostring();
System.out.println("elapsed time #2 = " + con.getelapsed());
// sanity check
if (!str1.equals(str2)){
System.out.println("str1/str2 mismatch");
}
}
}

------------------------------

read for more information,

http://www.roseindia.net/java/example/java/util/CapturedText.shtml









Related Pages:
BINARY TO DECIMAL - Java Beginners
BINARY TO DECIMAL  HELP ME PLSS. PROGRAM THAT CONVERTS BINARY TO DECIMAL  Hi friend, Program to convert Binary To Decimal : import... " + decimal); } } For read information on Java : http
Binary to decimal - Java Beginners
Binary to decimal  Need help pls.. i cannot run this program... pls correct my program... i really appreciate your answers... thank you very mucha... = Integer.parseInt(JOptionPane.showInputDialog("Input Binary:")); String c = args[0
swing program for decimal to binary
swing program for decimal to binary  swing program for decimal to binary
Convert Decimal into Binary
; a decimal number into a binary number.  Description of program: This program takes a decimal number from console and it converts it  into binary format... the Decimal number into binary number use toBinaryString() method. 
Java binary to decimal
Java binary to decimal       This Tutorial helps you to know the code for Java binary... you in understanding a how to get a 'Java binary to decimal'. For this we have
Convert Binary to Decimal
Convert Binary to Decimal      ... to convert the integer data into the binary to decimal.  Code Description.... Output of this program: C:\corejava>java BinaryToDecimal Enter
binary
binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. Thks
I converting binary to decimal and vice versa
I converting binary to decimal and vice versa  can i ask for the codes in converting binary to decimal and decimal to binary to be run in one program with repeat.. pls. help me! i badly need the codes by monday!! pls
program binary
program binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. In pascal language please
Java Convert decimal to binary using Stacks
Java Convert decimal to binary using Stacks In this section, you will learn how to convert decimal into binary using stacks. You all are aware of Stacks... have converted a decimal number into binary. Here is the code: import
java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve
Convert Number to Binary
). The given number is a decimal format and the following program to calculate its binary. Code Description: This program takes a decimal number at the console...: Output of this program given below. C:\corejava>java
java program (integer/decimal) - Java Beginners
java program (integer/decimal)  Accept a number from the user as command line arguments. The number could be an integer or decimal value. ? Display the absolute value of the input number ? Display the rounded off value
Java Conversion
will learn to convert decimal number into binary. The java.lang package provides the functionality to convert  a decimal number into a binary number.  ... number into hexadecimal. Convert Binary to Decimal In this section
Convert Binary to Hexadecimal
the binary data into hexadecimal.  Description of the program: This program takes... '0' or '1' , program converts the binary data into hexadecimal using...:\corejava>java BinaryToHexa Enter the Binary number: 1111111 Hexa
Convert Octal to Decimal
to decimal. The following program helps you converts number octal to decimal. ... of this program: C:\corejava>java OctalToDecimal Enter... Convert Octal to Decimal     
Convert Decimal to Hexadecimal
;} } Download this program. Output of this program: C:\corejava>java... Convert Decimal to Hexadecimal       In this section, you will learn to convert a decimal data
Convert Hexadecimal to Decimal
into decimal. The java.lang package provides the functionality to convert a hexadecimal number into decimal. Code Description: This program takes a hexadecimal... Convert Hexadecimal to Decimal     
Convert Decimal to Integer
a decimal number to an integer type number. Description Code: This program helps you...:\corejava>java DecimalToInteger Enter the Decimal number: 13... Convert Decimal to Integer      
Convert Decimal to Octal
. Description of code: This program takes a decimal number at console and converts...:\codejava>java DecimalToOctal Enter the decimal number: 26 octal:=32... Convert Decimal to Octal      
JAVA: Recusrion, Binary Search
JAVA: Recusrion, Binary Search  I want to learn about Binary Search..., Inheritance, Interface, etc for this program. I also know that this needs to be implemented into a lot of classes. So if you could figure out this program for me
Java Convert Octal to Binary
Java Convert Octal to Binary In this tutorial, you will learn how to convert octal to binary. Java has provide different ways to change the number system of different numbers. You can convert and decimal to octal, decimal to binary
decimal to hexadecimal
decimal to hexadecimal  using array in java convert decimal to hexadecimal.   Hi, Please see the example Convert Decimal to Hexadecimal. Thanks
binary search - Java Beginners
binary search  Write a java program to search an array by using recursive binary search.  /* * To change this template, choose Tools... program public static void main( String [ ] args ) { int SIZE
convert to decimal
convert to decimal  f42a4 convert to decimal by using java
Convert Decimal To Character
. This program takes a decimal value. Type casting (char) d ) is done...;java DecimalToASCII Enter the Decimal number: 65... Convert Decimal To Character     
Convert Decimal To Fraction
to Fraction. The following program you convert it into the decimal to fraction...; for the java component. This program takes a string type value and store it in an integer...:\corejava>java DecimalToFraction Enter the decimal number
Decimal Format Example
Decimal Format Example       In this example we are going to format a decimal value... "0.000" .This is used to create an decimal format which display
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
Integers
, .... Integers are represented in binary inside the computer, and in decimal in Java source programs. Java automatically converts decimal numbers you write in your source program into binary numbers internally. Four (or five) kinds
Convert integer type data into binary, octal and hexadecimal
into binary, octal, and hexadecimal. The following program helps you to convert... Convert integer type data into binary, octal and hexadecimal... will learn how to convert an integer type data into binary, octal and hexadecimal
converting From Hexadecimal to Decimal System - Java Interview Questions
converting From Hexadecimal to Decimal System  Write a program in Java user is required to enter a number system XVI and turn it into the decimal.../java/java-conversion/DecimalToHexadecimal.shtml  Hi Friend, Try
Java Write To File Binary
Java Write To File Binary In this tutorial you will learn how to write... types can be formed to a byte of 8 bits. Write to a binary file in java... process to execute a java program write simply on command prompt as : javac
Convert Text to Binary
Convert Text to Binary       In this section, we will learn how to convert Text to Binary. The following program provides you the functionality to convert Text to Binary
Convert Text to Binary
to Binary. The following program provides you the functionality to convert Text to Binary. Code Description: In the program code below, to take the input from... Convert Text to Binary      
binary addition,subtraction and modulus operations - Java Beginners
operations on these two binary numbers and finally dipaly the result in decimal... adder binary logic in this!!! please send me the java coding for these three...binary addition,subtraction and modulus operations  i wanna perform
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n; int i; rose(int n,int i) { n=173; i=371; } void out { System.out.println
binary tree
://www.roseindia.net/java/java-get-example/java-binary-tree-code.shtml http://www.roseindia.net/java/java-get-example/java-binary-tree-insert.shtml...binary tree  can a binary tree be implemented with out comparing
Convert Hexadecimal into Binary and Long
into the binary and long. At run time this program asks for a  a hexadecimal data... Convert Hexadecimal into Binary and Long   ... the hexadecimal data into the binary and long format. The java.lang package provides
Rounding off in Java - Round two decimal places
Rounding off in Java - Round two decimal places  ... to round the figure up to two decimal places in java.  Round...: The following program round two decimal places of the given number. It means
octal to binary
octal to binary  i want to know how to convert a octal to binary number   Here is a java example that converts octal to binary. import... binary=Integer.toBinaryString(i); System.out.println(binary
Binary Search - Java Beginners
Binary Search  how to use Binary think in java give me the Binary Search programm thx
Prepared Statement Set Big Decimal
data type in java to integrate in MySQL through the help of NUMERIC and DECIMAL...: In this program we are going to insert big decimal data type in the database table (bigdecimal... Prepared Statement Set Big Decimal   
Reading binary file into byte array in Java
Example code of reading binary file into byte array in Java This example shows you how to read a binary file into byte array from Java program. This type... of the Java program that reads the binary file into byte array: import java.io.
Java binary tree code
Java binary tree code     ... especially in mathematics and Boolean. The java binary tree find its application... in understanding Java binary tree code. For this we have a class name BinayTreeExample.Inside
Binary Search in Java
Binary Search in Java is used to search an element from an array. Programmers opt for Binary search over linear search when it comes to large numbers. It can... the answer "Not Found". Following is the example of Binary Search in Java: import

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.