Program in Java decimal to binary

Program in Java decimal to binary

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 Tutorials/Questions & Answers:
swing program for decimal to binary
swing program for decimal to binary  swing program for decimal to binary
Write a program in Java to convert Decimal number into Binary number
Write a program in Java to convert Decimal number into Binary number  Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? Thanks
Advertisements
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
How to convert binary to decimal in Java?
How to convert binary to decimal in Java program? In this section... concerts Binary to Decimal in Java. Computer is based on the binary number...: The parseLong() method is used to convert Binary to Decimal in our program
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
Conversion of Decimal to Binary in Java
Conversion of Decimal to Binary  in Java In this section we will discuss about conversion of Decimal to Binary in Java. You know that number having... as an  integer in base 2. Example : Code to convert Decimal to Binary using
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 Decimal into Binary
; a decimal number into a binary number.  Description of program:ADS_TO_REPLACE_1 This program takes a decimal number from console and it converts it .... To convert the Decimal number into binary number use toBinaryString() method
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
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
Convert Binary to Decimal
Convert Binary to Decimal      ... to convert the integer data into the binary to decimal.  Code Description:ADS... this program.ADS_TO_REPLACE_2 Output of this program: 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
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
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
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
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
Binary Search - Java Beginners
Binary Search  how to use Binary think in java give me the Binary Search programm thx
Java read binary file
Java read binary file  I want Java read binary file example code... at Reading binary file into byte array in Java. Thanks   Hi, There is many more examples at Java File - Learn how to handle files in Java with Examples
How to round a number to n decimal places in Java
How to round a number to n decimal places in Java  How to round a number to n decimal places in Java
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 Conversion
; In this section, you will learn to convert decimal number into binary. The java.lang package provides the functionality to convert  a decimal number into a binary... Binary to Decimal In this section, you will learn how to convert  binary
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
java binary file io example
java binary file io example  java binary file io example
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
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
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
Convert Octal to Decimal
to decimal. The following program helps you converts number octal to decimal.  Description of code:ADS_TO_REPLACE_1 This program takes an octal number... Convert Octal to Decimal     
Binary Search!!! - Java Beginners
Binary Search!!!  Hi Sir, My question is quite simple. im only getting "ArrayIndexOutOfBoundsException : 10" in the if statement which is inside the 1st while loop. How can i get rid of it? The if statement is btw
round double to 2 decimal places java
round double to 2 decimal places java  Hi, How to round double to 2 decimal places java? Thanks   Hi, BigDecimal class can be used in following way: import java.math.BigDecimal; import java.math.RoundingMode
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 be done either recursively or iteratively. The program checks the entered
decimal to hexadecimal
decimal to hexadecimal  using array in java convert decimal to hexadecimal.   Hi, Please see the example Convert Decimal to Hexadecimal. (adsbygoogle = window.adsbygoogle || []).push({}); Thanks
convert to decimal
convert to decimal  f42a4 convert to decimal by using java
How to write in Binary file in Java programming language
How to write in Binary file in Java programming language  I need some help about Java programming. Please explain me "How to write in Binary file in Java programming language
Convert Decimal To Character
? for java component. This program takes a decimal value. Type casting (char) d.... C:\corejava>java DecimalToASCII Enter the Decimal... Convert Decimal To Character     
binary distributions - Java Server Faces Questions
binary distributions  what are binary distributions
JavaScript for decimal number comparisons - Java Beginners
JavaScript for decimal number comparisons  Hi, I need to compare a BigDecimal in my javascript. I need a have a validation the text field value should not exceed (15,2) (max value is : 9999999999999.99). I am not able
How to using Binary Search Array Java ?
How to using Binary Search Array Java ?  Hi, I am beginners in Java... functions. The problem is that how to use binary search array in Java. Please give any online reference show that i will implement the binary search array in Java
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... is the complete code of the Java program that reads the binary file into byte array:ADS
Writing to and reading from a binary file in java.
Writing to and reading from a binary file in java.  I have written the following code to convert an ASCII text file to a binary file: public static... the binary file from another program as follows: m_dis = new DataInputStream
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... Description of program:ADS_TO_REPLACE_2 The following program round two decimal places
Inserting Comma in a decimal number - Java Beginners
Inserting Comma in a decimal number  Hi, I want to insert comma in a number that contains decimals also. How can I get 99,999.99 when I have 99999.99. Please tell me. I need it urgently. Thanks a Lot  Hi friend,import
Convert Number to Binary
). The given number is a decimal format and the following program to calculate its binary. Code Description:ADS_TO_REPLACE_1 This program takes a decimal number... Convert Number to Binary      
Java Binary data file - Java Beginners
Java Binary data file  Hi, I have a binary data file(binfile.data) and the file has what is commonly referred to as variable length... in the binary file.I have to do this using java.I tried to figure out the correct
Java program
Java program  I'm having troubles writing a program that upon... shows your height as a decimal. Thank you!   import java.io....". Also the decimal would be a separate answer, after showing the height in feet

Ads