Modify Code That Converts Binary Code To Decimal Numbers

Aug 29, 2014

The code here I have works fine if I just want to ask the user to enter four digits: //java application that asks user to input binary numbers(1 or 0) and convert them to decimal numbers import java.util.Scanner; //program uses class scanner public class binarynumber{
 
//main method that executes the java application
public static void main(String args[]){
//declares variables
 
int digit;
int base=2;
int degree;
double decimal;
int binary_zero=0;
int binary_one=1;
//create scanner for object input

[code]....

The thing is, I want the java application to input more than four digits for the user and I want it to loop it manytimes f until the user ask it to stop.

View Replies


ADVERTISEMENT

Code Converts A String That Has All Numbers Into Integer

May 8, 2015

I am trying to code using error handling and I am a bit confused on how to go about doing it correctly. My code converts a string that has all numbers into an integer and the error handling should recognize that if it isn't a proper number and ask the user to try again or enter 'q' to quit.Do I place a throw new exception in the try block and put conditionals like if charAt(i) is some letter or a symbol then throw new exception?

Java Code:

import java.util.Scanner;
public class practice {
public static void main(String[] args) {
Integer finalValue = null;
boolean validValue = false;
Scanner scan = new Scanner(System.in);
int result = 0;

[code]....

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

Modify Hub Code To Switch

May 26, 2014

I have a code for a Hub and I wanted to modify it to a Switch.. See the code below:

--- Update ---

package module.Hub;

import framework.Port;
import module.ModuleUI;
import java.lang.String;
import framework.Packet;

[code]....

View Replies View Related

Convert Java Code To Display Using Printf Statement With Two Decimal Places To Right

Feb 26, 2015

How i would convert this java code to display using the printf statement, with two decimal places to the right...here is the source code so far, but it has a few errors and needs to be reformated for printf

import java.util.Scanner; // scanner class
public class PROB3_CHAL15
{
public static void main(String[] args)
{
double checks =0,
totalfee =0,
fee = 10,
fee1 =.1,
fee2 = .08,
fee3 = .06,
fee4 = .04,
checkFee;
String input;
Scanner keyboard = new Scanner(System.in);
 
[code]...

View Replies View Related

Java Binary Tree Code

Apr 5, 2014

I have written a code to get all the nodes below a current Node and it is working but I need to get it to look better if possible. To get the number of nodes below I have created an Array List, which I then go to the first Node below and add all the people to the Array list on the same level till I get to the end of the level, then I go down again until I cannot go down any more. Is there a way I can have my code without having to use an array List? I have put my code below. The brieff about the tree is that you have a parent and below the Parent are children who can have brothers and sisters next to them and after that they also have children below that. The method is trying to find the number of children below any given child

private LinkedList<Node> TempQueue = new LinkedList<Node>();
public int noOfYoungerChildren(Member p1){
Node tmp = find(p1);
return countYoungerChildren(tmp);

[code]....

View Replies View Related

Binary Search Code For Array?

Mar 23, 2014

I'm just getting two errors concerning line 38 where it has Arrays.sort(int roomList); and the errors state that ".class is expected" and so is a semicolon. What did I do wrong? Also, how might I tweak the code to display "Occupied" or "Unoccupied" depending on the room that was entered?

Also we're not allowed to make use of API method for binary search so that's out of the question.

import java.util.Scanner;
import java.util.Arrays;
public class HotelRoom
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
int[] roomList = new int[25]; // occupied rooms

[Code] ....

View Replies View Related

Code Allows To Enter Negative Numbers -1

Apr 4, 2015

double CashInsert = Double.parseDouble(CashAmounttxt.getText());
System.out.println("Cash Received: " + "£" + CashInsert);
if (CashInsert<=0 &&(CashInsert <TotalPrice)){
ChangeLeft = CashInsert - TotalPrice;
System.out.println("Total: £" + TotalPrice);
System.out.println("Change Due: " + "£" + ChangeLeft);}
else {
System.out.println("Insuffient funds, please enter £"+ TotalPrice +" or More");}
}

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

Cash Received: £-1.0
Total: £4.85
Change Due: £-5.85

It allows me to enter -1 I've already coded it so the person cannot enter less but -1 works.

View Replies View Related

Sieve Code To Find Prime Numbers

Jan 16, 2015

I am doing a sieve code to find prime numbers.

public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter the maximum number ");
int maxNumber = scanner.nextInt();
int[]numberList = createList (maxNumber);

[code]....

I have a problem with the output. It only get as far as marking the multiples of 2. It does not mark the multiples of 3 and so on.Example output: If the range is from 2 to 15 the output is :2, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 15 note: 0 means its marked.As you can see it only marks multiples of 2 but it does not mark multiples of 3 above. I think the problem lies in the for loop inside my main method, because the index does not increment.

View Replies View Related

Simple Switch Code For Random Numbers

Feb 10, 2015

I am doing a project to generate three names of fruits. When I take out my switch code the numbers generate randomly, but when I added the switch code back I kept getting three instances of "Bars" as if the random numbers all became 5.

public static void main(String[] args)
{
System.out.println("Enter the amount of money you would like to gamble.");
Scanner keyboard = new Scanner(System.in);
int num1;
int num2;
int num3;
int money;
money = keyboard.nextInt();

[code]...

View Replies View Related

Web Services :: Code Implementation Generated By Axis2 Code Generator?

Aug 23, 2010

I was a bit confused of the code generated by the Axis2 Code Gen.

I have created a logIn(String username, String password) method in my service and used Axis2 Code Gen to generate the Stub.

I try to access the logIn method from my Client using the Stub like below:

TestServiceStub stub = new TestServiceStub("http://localhost:8080/axis2/services/TestService");
String test = stub.logIn("user","pass").

but instead of UserName and password as the parameters, the Stub created a Login object as the parameter for the logIn method. like the one below:

stub.logIn(Login login1);

I wanted to try the logIn method by providing a static userName and password but it seems impossible because the Stub changed the parameter for the logIn method.

how to test the logIn method.

View Replies View Related

Numbers Divisible By 6 - Code Is Giving Different Result Then Expected

Aug 22, 2014

I am having problems with writing a simple program to see if a number is divisible by 6.

public void run() {
println("This program will display all numbers divisible by");
println(" 6 between 1 and 100.");
int x =1;
boolean divide =(x%6==0);

[Code] ....

It is telling that every number is not divisable by 6?

View Replies View Related

Input Color Code In HSV And Output Equivalent RGB Code

Oct 9, 2014

I need to create a Java program that takes an input a color code in HSV and outputs the equivalent RGB code and Vice versa.

Example:
If you test on the color RED in RGB:
Input: (255,0,0)
Output: (0,100%,100%)
If you test on the color RED in HSV:
Input0,100%,100%)
Output: (255,0,0)

View Replies View Related

Display Two Numbers / Integer Code And Computed Result To Screen

Oct 26, 2014

Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen

here is the code that I have so far:

public static void main(String[] args) {
Scanner read = new Scanner (System.in);
int num1, num2, code, sum;
System.out.println("Please enter a number");
num1 = read.nextInt();

[Code] .....

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related

Binary To Decimal Using Array

Jan 28, 2015

I do not know how to convert a reversed array to decimal.

The output should be:

How many digits to convert?
(user will input) ex. 3
Please input digits:
(user will input 3 digits)
ex. 0
1
1
The binary digits are: 110 (<-reversed)
The decimal value is: 6

Here is my code:

package numbersystemconversion;
import java.util.Scanner;
public class BinarytoDecimal {
static {
int digit=0;
Scanner input = new Scanner(System.in);

[Code] ....

View Replies View Related

Convert Binary To Decimal Such As Bin

Sep 20, 2014

I am having an issue with my program. It is supposed to convert from a binary number to a decimal number such as bin 101 = dec 5. my first and foremost issue is that when I use System.out.println(parseBin("101")); it returns 5 as it should. However when I change 101 to 1013 it returns 13??? Why is this happening and why are my exceptions not catching the issue?

//import java.util.Scanner;
public class BinaryFormatException {
public static void main(String[] args) throws BinFormatException{
System.out.println(parseBin("1013"));
//Scanner input = new Scanner(System.in);
//System.out.println("Please enter a binary number using 1's and 0's: ");
//String binString = input.nextLine();

[Code] ....

View Replies View Related

Decimal To Binary - Not Getting Any Input

Dec 13, 2014

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

[Code] ....

I am not getting any output.........

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

How To Modify Text So That It Doesn't Contain Two Equal Numbers

May 3, 2014

I would like to create a program that takes some files and modifies them in this way: The files should contain text formatted in this way:

##############
#various comments#
##############
something{
identifier=1234
anotherIdentifier=1235
anotherOne=12345
//and so on...
}//I need only this
 
#Comments are sometimes made this way
 
somethingAgain{ 
#comments that explains what's below them
I:dentifier:something, I, do, not, need
#see ^that
A:notherIdentifier:boolean
//and so on..
}

And I have to make so that the numbers contained in something{} in all the files don't match. I could ask to make so that the input file is only one, and it is formatted this way:

identifier=1234
anotherIdentifier=1235
anotherOne=12345
//and so on...

but I don't know how to do the rest of the program... That's what I've done (the names of the classes, package etc. are in Italian and there's some useless code that NetBeans prevents me from deleting):

package confronto;
import java.awt.Color;
import java.io.*;
import javax.swing.*;
public class confrontoTesti extends javax.swing.JFrame {
 
[Code] ....

View Replies View Related

Printing Decimal Equivalent Of Binary Number

Feb 28, 2014

This problem is from Java . It asks me to convert a binary number in to decimal. How to program this in java? I am not able to find an effective algorithm to convert in to Java.

View Replies View Related

Input Binary Value And Convert It Into Decimal And Vice Versa

Jan 9, 2015

I am new to java programming and using bluej for programming and i have tried this question what i have have given in title ... How to do the following question without using strings.

Write a java program to input a binary value and convert it into decimal and Vice Versa. Without using String. Please make it for blue j format.

View Replies View Related

Numbers After Decimal Won't Add Together For Total

Sep 26, 2014

The code is below and the problem I am having is the numbers after the decimal won't add together for the total I am teaching myself java through liang's 10th edition book and I took one of the sample programs further than what was shown. The one in the book only shows the tax amount I simply wanted to make it so that the purchase amount and the tax amount would add together

package javalearning;
import java.util.Scanner;
public class FindingTax {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter Purchase amount: ");

[code]....

View Replies View Related

Display Decimal Numbers Only

Jul 6, 2014

What code to use to display decimal numbers only. for example 125.50. the program will only display .50

View Replies View Related

How To Print Double With 2 Decimal Numbers

May 3, 2014

I am trying to cast an integer into a double. it works but I need two decimal number after the dot and for example I can print 7.51 but how can I get it to print 7.50 and not 7.5

public int compareTo(Money o){
int d1 = (this.dollars * 100) + this.cents;
int d2 = (o.dollars * 100) + o.cents;
return d1 - d2;
}

On my main method I have

public static void main(String[] args){
Money money1 = new Money(10, 49);
Money money2 = new Money(2, 99);
System.out.println("result: " + "$" + (double)money1.compareTo(money2)/100);
}

It prints 7.5 but I want it to print 7.50, how do I do this .....

View Replies View Related

Double RelativeFrequency Value Which Does Calculation / End Result Is Number With Lots Of Decimal Numbers

Nov 24, 2014

for (int i = 0; i < letters.length; i++) {
double relativeFreq = (onesAverage()/letters[i]);
char a = characters.charAt(i);
double j = score[i];
System.out.printf();//ToDo

Above is my current code. Basically- There is a string called characters of length 26 (1 char for each letter in alphabet), a double relativeFrequency value which does a calculation and the end result is a number with lots of decimal numbers. The score array has set double values within the array.

What I want to do is create a print f statement where I print out each of the values I initialized above WITH specific amounts of spaces in between. So it should be in this order:

a (spaces) j (spaces) relativeFreq (newLine).

Between J and relativeFreq there should be 4 spaces, however if the value in relativeFreq is greater than 10 (it won't be greater than 100)- then there should be 3 spaces. Everytime I try to create a printf statement my code ends up crooked for some of the values.

for (int i = 0; i < letters.length; i++) {
double relativeFreq = (onesAverage()/letters[i]);
char a = characters.charAt(i);
double j = score[i];
System.out.printf("%c %.4s %.4s%n",a, j, relativeFreq);

View Replies View Related







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