I wrote this small program to take an octal number from the user and convert it to decimal form.
import java.util.Scanner;
public class Decimal
{
public static void main (String args []) //gets octal number from user, later prints conversion
{
int octal;
[Code] .....
Some conversions work. For example, 77 will be correctly converted to 63, and 77777777 will be converted to 16777215. However, some conversions do not work. An example of this is 775002 gets converted to 74898.
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.
I'm trying to convert an octal number into a decimal number. I keep getting a big error that says java:63: error: class, interface, or enum expected. i need to use a public static int convert ( int octalNumber ) along with a public static void main ( String args[] ).
Here is my code. />
[public static void main ( String args[] ) { int foo; int valid = 0; Scanner sc = new Scanner (System.in); System.out.print ("Enter up to an 8-digit octal number and I'll convert it: "); foo = sc.nextInt();
I'm doing a program where a user enters in exam results for students. Once he's entered the code, the code should split the results in stars in 4 categories.
I am working with a while loop that prints out infinite results. What I want to do is, if the user enters 2 digits, say "12", it should output 1 "*".
If the user enters "21" and "22", it should output "**".
There are 4 categories of marks which are marked with ints range1, range2, range3 and range4, which are user enter digits. Part 1 of the code is to split the user entered digits into its correct ranges. the ranges are 0-29, 30-39, 40-69 and 70-100. I've done the part where when the user enters a digit, it goes into the correct variable. After that when the user enters a digit over 100, the enter results should show up as stars. For example
Enter number =
21 22 44 66 44 23 11 111 (the 111 is where the program breaks and moves on)
So it should then display
0-29 ****
30-39
40-69 ***
70-100
Whatever I'm trying, it displays an infinite amount of stars. If I try to use break, It only outputs a single star, no matter how many digits I enter
Here is the code
int mark = 0; int range1 = 0, range2 = 0, range3 = 0, range4 = 0; int count1 = 0, count2 = 0, count3 = 0, count4 = 0; while (mark >=0 && mark <=100) {
[Code] .....
"The problem is with the while loop, the one above is something I was experimenting with "
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).
I am trying to teach myself a bit of java and came across the following line of code in the degrees to Fahrenheit converter tutorial:
int tempFahr = (int)((Double.parseDouble(tempTextField.getText()) )
* 1.8 + 32);
I know what the code does in that it is getting the value that the user has input in text field tempTextField and is applying the mathematical calculation to convert to Fahrenheit and assigning the result to the variable tempFahr.
I am guessing any value input into a text box is considered a string?I am guessing that Double.parseDouble takes in a string and converts it to a double.I am assuming that by simply putting (int) in front of
that it calculates the value and converts it to an int?The tutorial says this example is not localizable because the parseDouble method is not localizable - what does it mean by localizable?
This program requires knowledge of manipulation of Java String objects and methods. It also requires knowledge of Number System Conversions.
// Lab16MATH05st.java // The Number System Converter // This is the student, starting version of the Lab16MATH05 assignment.
import java.util.Scanner; public class Lab16MATH05st { public static void main (String args[]) { System.out.println("Lab16MATH05 - Number Conversion Program
[code]....
90-Point Version Specifics: The 90-point version requires that you write both the fromHexToBin and fromBinToDec methods.
90-Point Version Output
95-Point Version Specifics {The 95-point version requires everything from the 90-point version and adds the fromBinToHex method. For this version, you may assume that the binary number will have a multiple of 4 bits.
95-Point Version Output
100-Point Version Specifics: The 100-point version requires the same methods as the 95-point version; however, the fromBinToHex method needs to be improved so it can convert regardless of the number of bits.
100-Point Version Output
105-Point Version Specifics: The 105-point version requires everything from the 100-point version and adds the fromDecToAny method. For this version, the method needs to be able to convert from decimal to any base between 2 and 10. Base 16 is not required for this version.
105-Point Version Output
110-Point Version Specifics: The 110-point version requires the same methods as the 105-point version; however, the fromDecToAny method needs to be improved so it can also convert to base-16.
I am new to java and I am trying to learn a little about GUI. I found this problem of creating a converter for temp from farenheit to celcius. I have everything working, except for when I hit the converter button... it does not convert.
The assignment reads: Develop a Java program (F2C.java) for converting a temperature from the Fahrenheit to the Celsius scale. The program will read the temperature graphically using an input dialog box
(JOptionPane.showInputDialog) and will show also the result graphically on a message dialog box (JOptionPane.showMessageDialog).
I can get my input box to show, but I am unable to get to the output box
What I have came up with:
import javax.swing.JOptionPane; public class F2C { public static void main(String[] args) { // Enter Farenheit String Fahrenheit = JOptionPane.showInputDialog(
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.
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
I'm trying to do a program to convert roman numbers to arabic numbers. My problem is that I don't have the right to use Methods and Arrays. Only loops and if/else.
Im working on a roman numeral to arabic converter and all I had to do was fill out the conversion method romanToDecimal. But for some reason no matter what number I enter It always says my number is equal to one.
//Quiz 1 EC import java.util.*; class Roman { private String romanNum; private int decimalNum; public Roman(){ romanNum = "I"; decimalNum = 1;
I got part of this converter built and running fine but now it's getting weird. Specifically I am getting to the part where I have to count above ten which means things like attaching Vs to Is and Xs and suchlike.
I know I have to use an .append someplace, I am just not certain how to go about it. I've been playing with it some, but this is honestly the biggest thing I've built so far that actually *ran* so I'm afraid to poke too many holes in it... where do I start? It's not like I can invent another return string and concatenate them. R is what I've got.
package hello; public class RomansatHomans { public static void main(String[] args) { // input fed on this line loops through toRo and comes back as a String // R String R = toRo(23); // int D = froRo("x");
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?
Is there a good reason for which StringConverter is an empty abstract class instead of being an interface ?It could spare the overhead of an embedded object reference ...
I'm doing to create miles/kilometers converter. If I put the mile, converting to kilometer is right. However, if I put the kilometer, converting to mile comes out wrong value. Which part is wrong?
i am trying to run a command in terminal the code is below if i run the command in terminal it works fine however when i run it from netbeans with code below nothing gets printed. however if i run a different command such as (ip addr) it works fine?
public static void a() throws IOException{ ArrayList lister=new ArrayList(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("ps -ef | grep firefox");// the command i am trying to run to get pid of application InputStream stderr = proc.getInputStream();
I need to print certain information from an arraylist depending on the arguments the method has. I'm trying to print the last 3 methods from the database class but nothing is printing and I don't know what the problem is.
package hw3; import java.util.*; public class Driver { public static void main(String[] args){ /* Comments required PersonFileReader pfr = new PersonFileReader("person.dat"); ArrayList<Person> testData = pfr.readData(); Database db = new Database(testData); */
[Code] .....
On the driver class I just print what the methods from the database class do.
I develop a little app in javaee6 and jsf2. I have a search page which has a search form with 2 fields and a search button when i click search button the results should be displayed in searchresults page.
Issue: searchresults page is is not displaying records though it fetched records from table I'm able to achieve this using search bean as session scope but i want to use the scope as Requestscope.
how to display results in a PLAIN_MESSAGE. My program is converting hex to decimal and displaying the results. Here's the code:
package pkgfinal; import javax.swing.JOptionPane; import java.util.Scanner; public class Final { public static int Convert(String userInput, int base){ int running_sum = 0;
I have the code here to populate a GUI. I have the math and then print out and return a single number. I have tried to use setText in the class CalculateButtonHandler.
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class RectangleProgram extends JFrame { private JLabel lengthL, widthL, areaL, perimeterL, averageL;