Converting From Decimal To Hexadecimal - How To Output Correctly

Feb 24, 2014

import java.util.Scanner;
public class FindHexString {
public static void main(String[] args) {
String hexString = ""; //output a hex string
int decNumber;//decimal number to be converted
int storeInput; //copy f input decimal number

[Code] ....

I am trying to figure out how to convert from decimal to hexadecimal without using the java library function. This is just a guess. I could be wrong.

View Replies


ADVERTISEMENT

Decimal To Hexadecimal Number Conversion

Jul 16, 2014

Java programming, I decided to write a code today that would convert decimal numbers to hexadecimal numbers. Unfortunately, it does not compile. The error message is "cannot find symbol - variable A", and might be the same error for the other variables B,C,D,E,F.

Here is my code:

public class dec2hex
{
public static void main (String [] args)
{int nbr = 99;
char a = A;
char b = B;
char c = C;

[Code] ....

View Replies View Related

Converting RGB Value Into Hexadecimal In ToString?

Jul 15, 2014

how to write the toString to convert this output :

List:
side: 14 color: java.awt.Color[r=0,g=0,b=255]
side: 18 color: java.awt.Color[r=255,g=0,b=0]
side: 12 color: java.awt.Color[r=255,g=255,b=0]
side: 18 color: java.awt.Color[r=255,g=0,b=0]
side: 16 color: java.awt.Color[r=0,g=255,b=0]
side: 10 color: java.awt.Color[r=255,g=200,b=0]
side: 10 color: java.awt.Color[r=255,g=200,b=0]

to this output

side:14 color:#0000FF
side:18 color:#FF0000
side:12 color:#FFFF00
side:18 color:#FF0000
side:16 color:#00FF00
side:10 color:#FFC800
side:10 color:#FFC800

here is how i have it written now

public String toString()
{
return "side: " + side + " color: " + color + "";
}

View Replies View Related

Convert Hexadecimal To Decimal WITHOUT Using Integer ParseInt Method

Mar 12, 2014

So I have to write a java program that converts hexadecimals to decimals without using the whole "integer.parseInt(AB1, 16)" method. I tried looking up how to do this but every forum/site I went to used this same method.

View Replies View Related

Converting Octal To Decimal

Sep 26, 2014

I'm trying to complete a code to convert decimal to octal. however i can't figure out how to print the output correctly. it should be.. Your integer number 160000 is 0470400 in octal. (160000 is the number you input). My code is...

Scanner input = new Scanner(System.in);

int value;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
String result;

[Code] .....

Lastly, my output prints everything correctly, but the input number always is 0.

Ex error: input= 160000

Your integer number 0 is 0470400 in octal.

it should be.. Your integer number 160000 is 0470400 in octal.

View Replies View Related

Converting Double Value To A 2 Decimal Place Value

Jan 28, 2015

I am trying to convert the double grossPay to 2 decimal places but cannot get it to work ,I am unsure of the correct way of doing this but this is how far I can get

public static double grossPay(double Orate, double overtime, double salary) {
double grosspay = 0;
grosspay = (Orate * overtime) + (salary / 26);
DecimalFormat df = new DecimalFormat("#.##");
return(df.format(grosspay));
}//closes grossPay method

View Replies View Related

Converting From A Vector Containing Big Decimal To A Float

Mar 13, 2015

I'm having extreme difficulty in working with a Vector storing a column with a BigDecimal value, and converting that single value into a float. I'm not sure why the code was written this way, but basically, I'm working with something called a vector that has a single Big Decimal value/column (not sure what the correct terminology is), and I want to store that value in a float variable called "dp". However, I don't know how to convert from the Big Decimal to a float.

Code is below:

String s = "";
sql = "SELECT DiscountPercentRate FROM Attendees WHERE AttendeeId=" + attendeeId;
  Vector v2 = sqldb.getResults(sql); /*I know that sqldb.getResults(sql) returns a vector with a single BigDecimal column of 15.0, in the test example I'm using*/
if (!v2.isEmpty()) {
Vector data2 = (Vector)v2.elementAt(0);
if (!data2.isEmpty())

[Code] .....

In case you're wondering what the sqldb.getResults() method looks, like, here's a snippet of it - There's an else statement that triggers in my case, adding a BigDecimal column to a vector, and returns that vector.

Vector v = new Vector();
...
else {
BigDecimal bd = rs.getBigDecimal(i);
vCols.add(bd);
}
v.add(vCols);
...
return v;

How can I take the single result of my SQL query in that Vector/Big Decimal thing, and turn that result into a float value?

View Replies View Related

Converting Primitive Data Types To Read Integers With Decimal

Sep 13, 2014

I get an error when I try to divide 500 miles by 25.5 gallons

Exception in thread "main" java.lang.NumberFormatException: For input string: "25.5"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at Mileage.main(Mileage.java:42)
Java Result: 1

[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

Format Output Correctly Using Printf Function

Nov 6, 2014

I have an output of three columns, Total Income | Tax Payable | Net Income... however to output this I have the following code:

System.out.println(" Total Income | Tax Payable | Net Income");
int i = 0;
 for (i=0; i <=18; i++){
if(incomes[i] < 0){
break;

[Code] ....

And the format of it comes out as: Screen Shot 2014-11-06 at 22.50.25.jpg

I'm getting very OCD about the format and I know there is a printf function which would solve this, however I don't really know how to use this correctly and it just messes up when I try to use it.

View Replies View Related

Floating Point Precision - Output With Two Decimal Places?

Jan 27, 2015

Consider this small program and output.

public class Floating{
public static void main( String[] args ){
System.out.println( 2.80 - 1.75 );
}
}

The output is 1.0499999999999998. Why not 1.05?

View Replies View Related

Type Casting - Getting Number With Two Decimal Places As Output?

Jun 7, 2013

"Type Casting" .... So the question is "How am I getting a number with two decimal places as output?"

import java.util.Scanner;
public class SalesTax
{
public static void main(String[] args) {
double purchase, tax;
Scanner input = new Scanner(System.in);
System.out.print("Enter purchase amount: ");
purchase = input.nextDouble();
tax = purchase * 0.06;
System.out.println("Sales Tax: $" + (int)(tax * 100) / 100.0); +//this will give two decimal places??+
}
}

View Replies View Related

Converting The Output Of Table To Float Point Value

Apr 26, 2015

I created this program to display a square root table. Problem is all of my output is too long. I would like to round the number to 4 spaces past the decimal. Here is my code:

public class MySqrt5_2 {

public static void main(String[] args) {
System.out.println("Number SquareRoot");
int[] table;
table = new int[21];
for (int counter = 0; counter < table.length; counter += 2) {
System.out.println(counter + " " + Math.sqrt(counter));
}
}

}

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

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

Semantic Error In Hexadecimal Converter

Jun 29, 2014

I'm sure the solution is simple, but I cannot find it.

/*reads a hexadecimal number input by the user and gives the corresponding base-10 value
*/

public class HexConverter
{
static int i; //used to keep place in the hexadecimal sequence given by user
public static void main(String[] args) {
//declaration of variables
String hexgiven; //the hexadecimal sequence given by user

[Code] .....

View Replies View Related

Hexadecimal Java Base Converter

Apr 28, 2015

I am writing a program that converts any base 10 number to bases 2-16. I have the code for everything up through hexadecimal conversion, for that requires the use of letters. I understand an array list may be of use however I do not understand how to use that in this code. Below is what I have so far

import java.util.*;
import java.io.*;
public class convertBase
{
public static void main(String[] args)
{
int base;
int number;
String newNum;
 
[code].....

I commented out the hexadecimal portions.How would I go about coding for letters?

View Replies View Related

Not Getting Decimal For Surely Decimal Answer?

Jan 1, 2015

I'm using eclipse. I'm going to get straight to the point and give all the info I can, if the values in the first code box are used, shouldn't these values be left after all in the second box is done:

remainder=23, arr[0]=100, div=23/10=2.3, whole=2, and decimal=3?

When I use this code, div comes out to be just (2.0).

Java Code:

int leng=10;
arr[0]=123; //int
arr[1]=100; //int mh_sh_highlight_all('java'); Java Code: if (arr[0]!=arr[1]){
int remainder=arr[0]-arr[1];
arr[0]=arr[0]-remainder;
double div=remainder/leng; //double div=Double.valueOf(remainder/leng);
int whole=(int) Math.floor(div);
int decimal=(int) ((div-whole)*leng); mh_sh_highlight_all('java');

I'm not sure were I'm going wrong in how div is being calculated, but I ultimately need div to be 2.3.

I've also used the second option commented out which still gives (2.0).

View Replies View Related

Round Decimal Number Into 2 Decimal

Apr 2, 2014

Here is my code and i want to convert number into 2 decimal but this code not give me result how to check my code.

import javax.swing.JOptionPane;
public class showtime{
public static void main(String[] args){
double total_mili=System.currentTimeMillis();
JOptionPane.showMessageDialog(null,total_mili, "Total milisecond",JOptionPane.INFORMATION_MESSAGE);
double seconds=total_mili/60;
double sec=(double)(seconds * 100) / 100.000;
JOptionPane.showMessageDialog(null,seconds, "Total Second",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,sec, "Total Second",JOptionPane.ERROR_MESSAGE);
}
}

View Replies View Related

Why If Statement Isn't Working Correctly

Apr 23, 2015

I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.

import java.util.Scanner;
public class InventorySystem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int count=0;
int inputEntered=0;
int numberOfItems=0;
double cost=0.00;
String item;
String description;
 
[code]...

View Replies View Related

How To Read A File Correctly

Feb 13, 2014

So i am creating a File object which has a text file passed to it. I then try to do logic with it using a BufferedReader. However, I get a FileNotFoundException on the using my code below. The Error is on the BufferedReader line. I

Java Code: System.out.println("--Reading text file--");
File file = getFile(c,fileName) // Returns a File object.
System.out.println(file); // Shows me the file is looking correct. Displays contents to console.
BufferedReader br = new BufferedReader(new FileReader(file));
System.out.println("BUFFERED");
while((line = br.readLine()) != null) {
try {
// Do Logic
}
catch(Exception ex){
ex.printStackTrace();
}
br.close(); mh_sh_highlight_all('java');

View Replies View Related

If Else / Switch Not Outputting Correctly

Jan 27, 2014

Trying to learn switch statements. Can't figure out what I am doing wrong.

java Code:

import java.util.Scanner;
public class Ok1 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

[code]...
When I run, it makes me enter letter = null and it wont output correctly.

View Replies View Related

Write Correctly Border And Gravity

Sep 27, 2014

I want to write simple game. Why if I press button UP and RIGHT it not move diogonally, may be it have special code. And how I need to write correctly border and gravity?

public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Stickman");
Ground ground = new Ground();
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(710, 480);

[code]....

View Replies View Related

GCanvas In ACM Graphics Not Working Correctly

Mar 25, 2014

I am trying to implement a game using the ACM graphics. For the game, I am trying to make the main frame a Grid of Cells.I made a Grid class which extends GCanvas:

import acm.graphics.GCanvas;
public class Grid extends GCanvas{
private final static int WIDTH = 300;
private final static int HEIGHT = 300;
private final int DIMENSION = 5;
Cell[][] grid;

[code]....

View Replies View Related

Game Over Method Not Updating Correctly

Sep 4, 2014

If I run this code. I can manipulate it so that X wins. When the third X button is pressed, there is no display saying that X has won and that the game is over. I have read over this code for days and still have not figured it out.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 public class TicTacToe extends JFrame implements ActionListener, WindowListener{
 public JFrame window = new JFrame("window");

[Code] ....

View Replies View Related

How To Drag JLabel Correctly Across JFrame

May 26, 2014

I am currently trying to make a method that will enable a jLabel to be dragged across the screen. I want to be able to drag the object pretty much anywhere on the screen(I hope to eventually make a destination for it where it can be dropped but I will get to that later). I have looked on various places on the internet on how to achieve this and the most simple solution does something like this:

Java Code:

jLabel6.setText("jLabel6");
jLabel6.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
jLabel6MouseMoved(evt);
}
});
private void jLabel6MouseDragged(java.awt.event.MouseEvent evt) {
x = evt.getX();

[Code]...

This actually works somewhat but it is very faulty. For example the jLabel keeps appearing and reappearing as I drag it. Furthermore when I drag it I can see a duplicate Jlabel being dragged as well in the top left hand screen. So how might I fix this?

View Replies View Related







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