For Loop To Convert Any Number Entered To Base 10 With Any Base Provided

Oct 9, 2014

So i'm writing a for loop to convert any number entered to base 10 with any base provided as well. My code does not work because I need a way to reverse the code order, so the new number is printed correctly with the given base. My code so far:

public static void main (String[] args) {
Scanner kb = new Scanner (System.in);
System.out.print("Enter a number :: ");
int numOriginal = kb.nextInt();
System.out.print("Enter a base :: ");
int base = kb.nextInt();

[Code] .....

newBase has a problem with how it calculates the new number, looking for correct newBase code for conversion?

View Replies


ADVERTISEMENT

Program To Convert A Base 10 Integer To Any Base 2 - 16

May 5, 2013

I am writing a program to convert a base 10 integer to any base 2-16. Here are the terms:"The method is to convert the decimal value the user selected into whatever base the user selected and print the converted value one place value at a time by using an index into an array of characters 0-9 amd A-F that is initialized to contain those characters.In the method you will find the largest place value (i.e. power of the base) that will divide into the decimal number.

Then you can set up a loop that will operate from that power down to and including the 0th power to determine how many times each place value goes into the decimal number. Using the loop counter, index into the character array to print the character that corresponds to the quotient number and then subtract the product of the place value and the quotient from the decimal number. With the power (loop index) decreased, repeat until you finish the 0th place value. Here's what I have so far:

import java.io.*;
import java.util.Scanner;
public class ConvertIt
{//start program
public static void main(String[] args)
{//start main
Scanner input = new Scanner(System.in);
System.out.println("Enter a positive integer from 0 to 10000.");
int number = input.nextInt();

[code]...

View Replies View Related

Java Base N To Base M Conversion

Jul 18, 2014

We were asked to do a program in java that could convert Base n to Base m. and im really having trouble with it.

View Replies View Related

Servlets :: Getting Path Of The Base URL?

Feb 5, 2014

I have a data.json in my J2EE web app.I need to load it either from local path when unit testing or from url when the server starts up.

so I've set it to get the local path by default and what I'm trying to do is that it is is running on a server, I'd like to change the path to a url.

Here is my code:

public String getUrlBase(HttpServletRequest request) {
URL requestUrl;
try {
requestUrl = new URL(request.getRequestURL().toString());
String portString = requestUrl.getPort() == -1 ? "" : ":" + requestUrl.getPort();
return requestUrl.getProtocol() + "://" + requestUrl.getHost() + portString + request.getContextPath() + "/";
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}

which works fine. The only issue is that I had to place this in the login page. Is there a way I can only set the path to the base url upon server start up?

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

Base Form For Add / Edit / Delete

Sep 7, 2014

I have been developing what I intent to be a base class for several forms that will allow the user for adding / editing / deleteing records. These records could be customers, products, suppliers etc.

I have designed a basic form that has an add, edit and delete button. For the add button, I would want to clear all the values in all of the controls (textboxes, combox etc) in preperation for adding a new record.

My question is this. Is this something I should do in the base class OR should it be handled in the classes that will extend from the base class? Perhaps if the controls were datalinked to the data they will clear themselves (I haven't got that far yet so I dont know). I thought maybe I could write code in the base class that could loop through all of the controls and call this from the extended classes.

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

How To Use Exception Handling As Base Class

Jun 17, 2014

I want to use my given code as base class

Java Code:

public static void file(String[] arg) throws IOException{
BufferedReader in;
String line;
try{
System.out.println("Reading word");
in =new BufferedReader(new FileReader("inp.txt"));

[Code] .....

View Replies View Related

Program To Change Base Of Integer Decimal

Nov 2, 2014

I know how to do this program it is just not coming to me. The whole point is to calculate and display the base (base-2 or binary, base-8 or octal and base-16 or hexadecimal) in representation of 'N'. The symbols A, B, C, D, E, F should display 10, 11, 12, 13, 14, and 15 in hexadecimal system.

import java.io.*;
import java.util.Scanner;
public class ChangeBase
{
public static void main(String[]args) {
double num;

[Code]...

View Replies View Related

Scientific Method - Compute Base Times 10 To Exponent

Feb 13, 2015

This is what I need to do: Write a method called scientific that accepts two real numbers as parameters for a base and an exponent and computes the base times 10 to the exponent, as seen in scientific notation. For example, the call of scientific(6.23, 5.0) would return 623000.0 and the call of scientific(1.9, -2.0) would return 0.019.

This is the method I have written:

public double scientific(double num1, double num2); {
double base = num1;
double exp = num2;
double scientific = base * Math.pow(10, exp);
System.out.println(scientific);
return scientific;
}

These are the following error messages I received when trying to compile the code:

Line 4
missing method body, or declare abstract
missing method body, or declare abstract
public double scientific(double num1, double num2);

[Code] .....

How to fix each error?

View Replies View Related

Java App To Open A Console Base Program And Run A Command

Jan 13, 2015

I am struggling getting my java app to open a console window on either MacOS or windows and run a command. On windows I can get the cmd.exe program to open, but it won't execute the command. On MacOS, I cannot get it to even open the terminal.

String run = "c:
s34bil.exe
elap5.exe" + in + rst + out; //in, rst, out are parameters for the relpa5.exe file.
try {
Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"cmd.exe","/c",run,"start"});
} catch (IOException ex) {
Logger.getLogger(issrsUI.class.getName()).log(Level.SEVERE, null, ex);
}

View Replies View Related

Private Var Won't Save Value Of Public Getter Function From Base C

Sep 15, 2014

I'm working on this program for a class to create objects of a commissioned employee and union employee. Everything seems to work ok, but when I run my final pay calculation, one of my getter functions will not pass the variable for the pay into a class specific variable called check. here is the code in this function.

public void finalPayCal_U() {
setweekPay();//calculates weeks pay under 40 hours, stored in getweekpay
check = getweekPay();
if(getHours() > 40){
check = check + (1.5 * (getHours() - 40) * getRateOfPay());
}
check =- Dues;
}
}

The issue lies in check = getweekPay();

I thought this was a legal move, but I can't get it to work. It doesn't come back with anything more than 0 any time I run it.

All of these functions are out of the base class, employee (this function itself lives in the derived union class)

public void setweekPay() {
if (hours <= 40) {
weekPay = hours * rateOfPay;
} else {
weekPay = 40 * rateOfPay;
}
}

When I run, this function works as it returns the value when i print it to test.

however, when I do the part that says check = getWeekPay() above, it doesn't change the check variable. The only thing I have on the check variable is the dues taken out of it at the end, so it ends up being a negative number.

I have a similar problem with the other derived class's check variable. Both classes have the same variable as private but one is check the other checkC.

View Replies View Related

Swing/AWT/SWT :: Changing Color Of Jtable Base On A Row Of Cell Value In One Column

Feb 10, 2014

My code is

Double qty = 0.0;
for ( int i = 0; i < ingTable.getRowCount(); i++){
qty = (Double) ingTable.getValueAt(i,2);
if( qty < 30.0){
ingTable.setBackground(Color.red);
} else {
ingTable.setBackground(Color.white);
}
}

View Replies View Related

Program For Class To Request User Input For Base Salary

Feb 24, 2014

I had to write a program for class to request user input for base salary, number of years worked, and total sales. Then use the data to find out the employee's paycheck when including a bonus. I have a few issues with the code, as I have one bug, then it won't calculate anything. what I'm missing?

package chapterone;
import java.util.Scanner;
public class Examplelab {
static Scanner console = new Scanner(System.in);
public static void main(String[] args){
double baseSalary;
double noOfServiceYears;
double totalSales;

[Code]....

View Replies View Related

Accessing Private Field Of Derived Object In Base Class?

Apr 1, 2013

I have this piece of code I wrote a while ago to test something. The issue is accessing a private field of Base class in Base but of a Derived object.

Here is the code:
class Base
{
private int x;
public int getX()

[Code]....

The commented code does not work but casting d to Base does.

Forgot to mention that the compilation error is that x has private access in Base.

View Replies View Related

Allow Input To Loop Until 0 Is Entered For Product Number

Sep 15, 2014

What I am trying to do here is allow input to loop until 0 is entered for the product number. When 0 is entered, it should then dump the total for each individual product. I've tried it about a dozen different ways and have yet to be able to get the loop to function as intended. The way I have the code below, the loop will not function at all (where as before it looped, but never finished).

import java.util.Scanner;
public class Sales {
public static void main(String[] args) {
double total1=0.0;
double total2=0.0;
double total3=0.0;
double total4=0.0;
double total5=0.0;
int product;

[Code] ......

View Replies View Related

Simple For Loop - Determine Factorial Of A Number Entered By User

Jun 28, 2014

I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.

What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:

class factorial {
public static void main( String[] args) {
Scanner scan = new Scanner(System.in );
int num;
int product = 1;

[Code] ....

View Replies View Related

Convert Strings To Double Numbers - Exception When Non-numeric Entered

Nov 11, 2014

So I have to convert strings to double numbers and there can be no exception.

The strings that aren't numbers or do not fit into a set criteria have to be discarded.

When I try to write this I get an exception when a non-numeric is entered and the code stops.

What can I do? Also, am I finding the average of the array correctly?

import java.util.*;
public class Grades{
public static void main(String args[]){
int arraycount = 0;
final int SIZE = 10;
int validArraycount = 0;
final int ValidArraySize = 10;

[Code] ......

View Replies View Related

Using While Loop For Printing User Entered Name From Console

Jul 2, 2014

Ask user to enter a name alphabet by alphabet, and print d whole word as output,,,,,, use while loop?Since i am new to JAVA..i have no clue on how to begin?

View Replies View Related

Switch Loop - Displaying Characters Entered Until Q Is Pressed

Jul 26, 2014

I cant apply my knowledge of the switch to modify this program.

What i need is that the program runs the same but i can press q to stop the program and it will continue in a loop otherwise. repeating the same process i.e displaying the characters entered until q is pressed.

How do i do it? I think i need to make use of do and while but how to apply those in this case.

View Replies View Related

How To Initialize To First Number Entered

Aug 10, 2014

initialize the min and max to be the first numbers entered, need to improve the code, because if the number entered is < 0 there is an error. but i dont understand how i would initialize to the first number entered, my understanding is tha if the user enters a 5 , then i should initialize to value 5, but i cant anticipate what the user will enter. I could initializa to null, but that still is not the first number entered.

int min = 0;
int max = 0;
int option = JOptionPane.YES_OPTION;
while ( option == JOptionPane.YES_OPTION){

[code]....

View Replies View Related

If Statements - Each Number Entered In Greater Than Zero

May 9, 2014

write a program that will ask the user to enter five numbers.using If statements if each number entered in greater than zero

import.java.util.Scanner;
public class Java3 {
public static void main(String[] args) {
function addNumbers(n1, n2, n3, n4, n5){
var finalNumber = 0;

[Code] ....

addNumbers(1, 2, 3, 4, 5,);

View Replies View Related

JSP :: How To Format Entered Number On Textbox

Apr 24, 2014

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber type="currency" value="12345.6789"/></p>
<input type = "text"/>

This one is working if i set value in fmt but what i want to happen is when i enter a number in textbox it will be fommated on the format that i want, so i think i need to an of og text and set it into value of fmt? <y plan is when I enter a number in textbox it will automatically formatted ....

View Replies View Related

Find If Number Entered By User Consecutive Or Not

Feb 21, 2014

I need to find if the number entered by the user are consecutive or not!

Ex:this should return a true!! This should return false!

(1,2,3) (3,5,7)
(3,2,4) (1,2,2)
(-10,-8,-9) (7,7,9)

My program seems to work ok when i enter number in order like 1,2,3 = true , and all the numbers for false seem to be working as well! my problem is when i enter number like 3,2,4 that are not in order but still are consecutive!! I thought that another if statement would be the solution but i have tray several different ones and still can't make it work !!!

Java Code:

import java.util.*;
public class Consecutive{
public static void main (String [] args){
Scanner console= new Scanner(System.in);
System.out.println("Enter three numbers");
String numbers = console.nextLine();

[[Code] .....

View Replies View Related

Find ASCII Number Of Names Entered

Sep 12, 2014

I am having a problem with SD array .i have to find the ASCII no. of names entered.

import java .io.*;
class ASCII
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);

[Code] .....

View Replies View Related

Program Should Exit Repetition Loop And Compute And Display Average Of Valid Grades Entered

Oct 26, 2014

My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.

When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.

//stephanie
import java.util.Scanner;
public class gradeAverage
{
public static void main(String[] args)

[code]....

View Replies View Related







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