Write A Program For Converting Positive Binary Inputs Into Hex

Sep 29, 2014

I am trying to write a program for converting positive binary inputs into hex.Why am i getting this errors while compiling my binary to hex converter..

Exception in thread "main" java.lang.NumberFormatException: For input string: "148.0"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Long.parseLong(Long.java:441)
at BinToHex.convertbintohex(BinToHex.java:24)
at Test.main(Test.java:4)

Here is my BinToHex class

import java.io.*;
public class BinToHex {
double tempDec,fractionpart;
long longofintpart,templongDec;
String inpu ="1001.01";
String hexOutput,intpart,tempDecString,hex = null;

[code]....

View Replies


ADVERTISEMENT

Program For Converting Positive Binary Inputs Into Hex - Unexpected Output Java

Sep 30, 2014

I am trying to write a program for converting positive binary inputs into hex. in the hex output the point (".")is missing.

Suppose my expected output is e7.6 , but i am getting e76.

Only the "." is missing.

Here is my BinToHex class..

import java.io.*;
public class BinToHex {
double tempDec,fractionpart;
long longofintpart,templongDec;
String inpu ="11100111.011";
String hexOutput=null,tempDecString,hex = null;
 
[Code] .....

Here is how decimal fraction is converted into hex or here too...

View Replies View Related

Converting Positive Binary Inputs Into Hex - Unexpected Output Java

Sep 30, 2014

I am trying to write a program for converting positive binary inputs into hex. in the hex output the point (".")is missing.

Suppose my expected output is e7.6 , but i am getting e76

only the "." is missing.

here is my BinToHex class..

import java.io.*;
public class BinToHex {
double tempDec,fractionpart;
long longofintpart,templongDec;
String input ="11100111.011";
String hexOutput=null,tempDecString,hex = null;
static int i = 1;

[Code] ....

View Replies View Related

Write A Java Program That Reads A Positive / Non-zero Integer As Input

Aug 1, 2011

Write a Java program that reads a positive, non-zero integer as input and checks if the integer is deficient, perfect, or abundant.

A positive, non-zero integer, N, is said to be perfect if the sum of its positive proper divisors (i.e., the positive integers, other than N itself, that divide N exactly) is equal to the number itself. If this sum is less than N, the number is said to be deficient. If the sum is greater than N, the number is said to be abundant.For example, the number 6 is perfect, since 6 = 1 + 2 + 3, the number 8 is deficient, since 8 > 1 + 2 + 4, while the number 12 is abundant, since 12 < 1 + 2 + 3 + 4 + 6.

SAMPLE OUTPUT:

1.)Input N: 5

5 is deficient.

2.)Input N: 6

6 is perfect.

3.)Input N: 18

18 is abundant.

View Replies View Related

Write A Program That Prompts User To Enter Two Positive Integers And Prints Their Sum

Jan 9, 2015

Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:

Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.

import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();

[code]....

View Replies View Related

Write A Program Where User Inputs A Month Between 1-12

Sep 21, 2014

I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java

The code:

import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");

[code].....

I think I have just forgot to put in a few { } symbols, maybe an open loop?

View Replies View Related

How To Save Results / Inputs For A Binary Search Algorithm

Apr 24, 2014

Is there a way that I can save a binary search algorithm to a text file or something, so that it will always contain more information? The reason why I ask this is because I have BST like project which is supposed to act the game Twenty Questions, were it asks a person 20 Q's until it guess the answer. However, although my project does not require you to save stuff to a file, I find it rather very useful and cool if I could do that.So for example it would start out something like this:

Think of an animal and I will guess it.
Does it have legs? YES
Is it a cat? YES
I win! Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? YES
I win! Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? NO
I give up. What is it? EARTHWORM
Please type a question whose answer is yes for an earthworm and no for a snake.
DOES IT LIVE UNDERGROUND?
Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Does it live underground? NO
Is it a snake? NO
I give up. What is it? FISH
Please type a question whose answer is yes for an earthworm and no for a snake.
DOES IT LIVE IN WATER?
Continue? NO
Good-bye.

However, if the user exits the program then everything will be lost and go to waste. So once again, is there a way that I can save all of these inputs to a file or something and then read it in again?

View Replies View Related

Converting User Input Binary To Integer

Sep 7, 2014

I am new to java and programming in general. I figured out how to convert an integer input to binary however I am having issues doing the opposite of converting a user input binary number to a decimal.

I need to do this with basic math (or string depending on how I represent the binary) and no functions.

I know how to convert binary to integer on paper but I am having a hard time working it out in java.

View Replies View Related

Manual Code For Converting Binary Octa / Hexa And Decimal

Aug 25, 2014

There's a main menu choosing binary,octa,hexa,and decimal if i choose decimal it will display decimal menu and then i will input the numbers of binary and then it automatically display the converting process for octa hexa and decimal. and if i choose octa . It display the octa menu and i will input the numbers in octa and then it automatically display the converting process for binary hexa and decimal.. and so on.. but in binary if i input 2 it will display invalid .. the same as octa hexa and decimal... in my code the only problem is the converting process. our instructor said no one will use a converter for our project. we will code it manually ..so for a moment .. this is my code..

import java.util.*;
import java.lang.*;
public class mainmenu {
public static void main (String[]args) {
Scanner in = new Scanner(System.in);
char B, O, H, D, Q, L, N , Y;
char bin , pk, pick ;

[code]....

View Replies View Related

How To Write Binary Search Iteratively

Apr 11, 2015

I am writing binary search method. I don't want to use recursive way, I want to write this method iteratively

Java Code:

public boolean binarySearch(int[] T, int min, int max, int target)
{
int mid=(min+max)/2;
boolean found = false;
int index=0;
while (!found && T.length <= 0 )
{
if (target == mid)
{
found = true;

[Code] ....

View Replies View Related

Program That Accept Input Of Positive Integer And Sum All Digits

Jan 28, 2015

I am attempting to write a program that accepts input of a positive integer, reports each digit and then the sum of all digits. This is what I have so far:

*/
 package numbersum;
import java.util.*; 
public class Week4NumberSum {
static Scanner console = new Scanner(System.in); 
/**
* @param args the command line arguments

[Code]...

It works if I enter 1234567891 (10 digits)
Enter a positive integer: 1234567891
digit: 1
digit: 2
digit: 3
digit: 4
digit: 5
digit: 6
digit: 7
digit: 8
digit: 9
digit: 1

The sum of the digits is 46

But if I enter 11 digits, it fails:

Enter a positive integer: 123456789123 (12)
Exception in thread "main" java.util.InputMismatchException: For input string: "123456789123"
at java.util.Scanner.nextInt(Scanner.java:2123)
at java.util.Scanner.nextInt(Scanner.java:2076)
at week4numbersum.Week4NumberSum.main(Week4NumberSum. java:26)

java - Scanner error with nextInt() - Stack Overflow gives me some infor for InputMismatchException - which I find described as In order to deal with this exception you must verify that the input data of your application meet its specification. When this error is thrown, the format of the input data is incorrect and thus, you must fix it, in order for your application to proceed its execution.

I don't understand why the 10 digit integer is OK but the 11 or > digit integer is a mismatch.

View Replies View Related

Relate Fraction Objects With Read / Write Methods Used In Binary I/O

Apr 25, 2014

We're learning how to use Binary I/O commands...which equates to....

My issue is trying to relate the Fraction objects (which we are to create using a loop) with the read/write methods used in Binary I/O (input/output streams). I left a blank after the output.write(), so you can see where the issue exist.

Java Code:

import java.io.*;
public class FractionTest {
public static void main(String[] args) {
int [] fraction = new int[3];
for(int i = 0; i <= fraction.length; i++){
Fraction numbers = new Fraction();

[Code] ....

View Replies View Related

Developing A Program That Inputs Telephone Numbers

Jan 26, 2014

Develop an algorithm for a Java program that takes as input a single letter and displays the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:

2 = ABC 3 = DEF 4 = GHI 5 = JK 6 = MNO 7 = PQRS 8 = TUV 9 = WXYZ

The screen dialog might look like this: Enter a single letter, and I will tell you what the corresponding digit is on the telephone. R The digit 7 corresponds to the letter R on the telephone.

The program should display a message indicating that there is no matching digit for any non-alphabetic character entered by the user. Also, the application should recognize only uppercase letters. If a user enters a lowercase letter, the program should display an error message. Prompt the user with an informative message for the input value as shown above.

The application should include the input letter as part of the output.

Write the algorithm to solve this problem including steps for prompting the user, getting input from the keyboard, and displaying the results.

Write the Java program that you designed, using your algorithm as a guide. Use your algorithm as comments in the body of the main method.

Use proper indentation, and meaningful identifiers throughout the code.

View Replies View Related

User Inputs His Full Name In A String From Keyboard / Program Will Give His Initials As Output

Jan 5, 2014

Following is the code for my assignment where a user inputs his full name in a string from keyboard. It should be done using BufferedReader. The program will give his initials as output.

############################

For example: User inputs-> Ram Kumar Das

Program Returns-> R.K.D.

I am written the following piece of code. It does not return the correct output. If "Ram Kumar Das" is given as input, it gives R.K.K. as output. Arrays and objects are strictly not allowed.

Java Code:

import java.io.*;
public class Assignment
{
static int i=0;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String args[]) throws IOException

[Code] ....

View Replies View Related

Converting A Program Into Applet?

Sep 30, 2014

how to make an applet out of this program but can't seem to do it.

Java Code: import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JLabel;
import javax.swing.JFrame;
import java.io.*;
import java.util.Scanner;

[code]....

Technically, when you run the program, a gif page appears (that I put as a placeholder) and when you press the letter 'n' JCreator runs the program, displaying a character P on a .txt field made using the Notepad on Windows. You can move it left, right, down, and up andf it will move accordinly. However, each time I make such action, the compiler has to rewrite to whole .txt field with the new position.

My former tutor said that in order for it to be "real-time", we have to use an applet.

View Replies View Related

Base Converting Program

Jan 24, 2015

The idea behind this program is that the program prompts the user to input an initial base (2-36), which checks to ensure that it is a valid int, then asks for a number to convert (which is taken as a String), then it asks which desired base the user would like to convert said number to. I have a basic program that is not complete, but allows me to do a few conversions using convertTo. I believe that I am going to have abandon this method and try mathematically converting every number. This leads me to what I can and cannot do. I am unable to use the initialBase as a condition to know what kind of number i an converting. For instance, I don't know how to make program know that if "2" is the initialBase, that that means that the String is a binary number. THAT is what I'm having problems with.

Here is my initial program that has a few things that are copied and pasted from other bits of my code in my program:

XML Code: Url...

I have broken down what I (think I) need to do here: Check to see if the input base is 2, 8, 10, 16, or 32. Hint: Put the possible bases in an array, and check the input base against the array. Check to see if the input number is valid for the base. Hint: Create a String "0123456789ABC...V" and compare each input character with the first "base" characters of the String. Check to see if the output base is 2, 8, 10, 16, or 32. Hint: Use the same possible bases array you used in step 1 to verify the input base.Check to see if the input base is equal to the output base. If so, print the input number. Perform a conversion from the input base to base 10. Perform a conversion from base 10 to the output base. You do this in 2 steps because it's easier to check each conversion separately.Output the converted number.

View Replies View Related

Converting JFrame Program To Applet?

Jan 15, 2015

I have two programs written out which open up in a JFrame when run but now I need to make it an applet.

My sample code:

import java.applet.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

[Code] .......

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related

Program Converting Fahrenheit To Celsius Using For Loop (will Not Convert)

Sep 13, 2014

I am trying to write a program converting Fahrenheit to Celsius using a for loop. I get it to run and Fahrenheit goes to a hundred. My issue is that the Celsius just says 100 down the column and is not converting. I have tried messing with it, and can not figure what is wrong with it.

import java.util.Scanner;
public class Controlstatement {
public static void main(String[] args) {
double F = 1.0;
double Celcius = 100;
System.out.printf("%s%20s", "Farenheit", "Celcius" );
for (int Farenheit = 0; Farenheit <= 100; Farenheit++) {
F = Celcius * (Farenheit - 32 * 5.0/9.0);
System.out.printf("%4d%,20.2f", Farenheit, Celcius);
}
}
}

The output looks like this all the way to 100:

Farenheit Celcius
0 100.00
1 100.00
2 100.00
3 100.00

View Replies View Related

Program To Convert Binary To Decimal

Oct 13, 2014

I'm working on creating the Binary to Decimal program . hat is wrong with this part of my code. Why does it not take you into the loop.

import java.util.Scanner;
public class question5 {
public static void main(String[] args) {
System.out.println("Enter a Binary number. "); // collect
Scanner keyb = new Scanner(System.in); //

[Code] ....

View Replies View Related

GUI Java Program - Hex To Binary Converter

Mar 11, 2014

This code is for a GUI Java program that is supposed to convert back and fourth between two numbering systems. For example, binary to decimal or decimal to binary. I have created methods for some of the conversions however, I could successfully develop a method to convert from hex to binary. If you plan to run it to see what happens to the current method that I made please know that in the GUI the north end from left to right is as follows.

The textfield is for user entry of any type of data. The first combobox is for the user specifying to the program what type of data he or she entered. The second combobox is for the user to choose what he wants that data converted to. The button is to convert it. The south side has a textarea that gives out the results. Please note that only some of the conversions work so far. There are comments in the code to label which methods do what converisons. Need to find a method that will convert from hex to binary, what is wrong with the current method.
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
[Code] .....

View Replies View Related

Java Binary Encoder And Decoder Program

Aug 2, 2014

I have made a Java Binary Encoder and Decoder program and, to date, this is the program I have spent the most time developing.

I have ran Alpha tests to check the functionality is correct and it appears to work well. However I am more interested in the quality of my code ,

The code can be found over at: [URL] ....

View Replies View Related

Writing Binary Search Program And Keep Getting Errors

Feb 24, 2014

Java Code:

public class Search
{
public static final int NOT_FOUND = -1;
public static int binarySearch( int [ ] a, int x )
{
int low = 0;
int high = a.length - 1;
int mid;
while ( low <= high )

[Code] ....

I keep getting illegal start of expression at ={-3,10,5,24,45.3,10.5}

It says I have 12 errors and I have tried so many things to fix it and I just don't know what to change to make it work.

View Replies View Related

Writing A Program That Searches Array Using Binary Search

Jul 10, 2014

I'm (failing at) writing a program that searches an array using binary search, but I can't get it to work.

My code so far is this:

Java Code:

package sorting;

import java.lang.*;
import java.util.*;
public class sorteh {
public static void main(String [] args){
int[] array=new int [20]; //creates new array
for (int x=0;x<array.length;x++){ //populates array
array[x]=x*3+1;

[code]...

I copied what a website did for the sorting part, but if I have low=0 and high=19, wouldn't mid not be an int?

View Replies View Related

Program Keeps Prompting To Enter Correct Binary Number

Sep 10, 2014

I wrote a java program for my gui number converter app, the main purpose of this program is to make sure that user enters only a binary number for conversion from binary to other number formats. the problem is my program keeps prompting me to enter correct binary number, no matter if i enter correct binary number, it will still keep prompting me to enter correct number. Here is the code

import java.util.*;
public class test {
Scanner key = new Scanner(System.in);
String in;
int b;
public test()

[Code] .....

View Replies View Related

Translator Program That Will Convert English To Custom Binary

Aug 23, 2014

I am trying to make a translator program that will convert english to my custom binary. It works going from english to binary, but not going from binary to english.

import java.util.Scanner;
public class Translator
{
public static void main ( String [] args ) {
Scanner input = new Scanner( System.in );
System.out.print( "Would you like to convert English to Binary (yes or no)? " );
String answer = input.nextLine();

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved