Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vaibhav
Program in Java decimal to binary
1 Answer(s)      6 years and 6 months 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?


Advertisement
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
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
Advertisements
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
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...(Binary equivalent of 12). Example : Using this example we pass a decimal
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: 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 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.... Output of this program: C:\corejava>java BinaryToDecimal Enter
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 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
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
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
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
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
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
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 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
java binary file io example
java binary file io example  java binary file io example
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 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
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
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
Advertisements
 

 

 

DMCA.com