Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.
import javax.swing.JOptionPane; public class DigitsAndSum { public static void main (String[] args) { String str1; String str2; int int1 = 0; int int2 = 0;
Make a program which takes input from the user (6-digit number) and check how many times each digit gets repeated in the number. Java GUI was used (Netbeans 6.5.1).This is my code. I took the input via a JTextField named tf and displayed the output on JTextArea ta.
- arrays not used as we haven't studied them yet
int num= Integer.parseInt(tf.getText()); int no=num; if(num<100000) ta.setText("Invalid Input. Please Enter 6 digit number"); int n1= num%10; num=num/10; //stores last digit
[code]....
How do I omit the last 5 lines? This problem occurs whenever I input a digit with any recurring digit.What changes/additions should I make?
You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive).
The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.
The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately
a) Write a sequential (non-parallel) program that will accomplish above task. b) Write a concurrent (parallel) program that will produce the result of the above task.
Given a Numbers instance, whose fields are arrays of all the built-in Java numeric types (int, long, float, double, big-decimal, etc), write a method to sort all the numbers into a master list, and then print out the numbers where the number of digits past the decimal point is equal to the index of the number in the master list.
Is there a function in Java that will give me just the numbers after the decimal? I tried Decimalformat but couldn't get it to work. Here is what I have so far; however, I think I might be on the wrong track.
public class Numbers { public static void main(String[] args) { Byte bNum = new Byte((byte) -50); Integer iNum = new Integer(168); Long lNum = new Long(100000L); Short sNum = new Short((short) 10000); Float fNum = new Float(12.19f); Double dNum = new Double(23.123); BigDecimal bd = new BigDecimal("3.14159265358979323846");
You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive). The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.
The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately
a) Write a sequential (non-parallel) program that will accomplish above task. b) Write a concurrent (parallel) program that will produce the result of the above task.
I have returned with yet another problem but I think this one might be a bit easier to fix.
So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:
"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int return result; ^
I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).
import java.util.Scanner; public class Exercise6_2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a integer"); long n = input.nextLong();
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
Spacing code: import java.util.*; public class SumoftheIntegers { static Scanner console=new Scanner(System.in); public static void main(String []args) { int num1, test, rem; int counter = 0;
[Code]...
Now the sum of the integers code:
import java.util.Scanner; public class sum { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Enter amount System.out.print("Enter an integer: "); int integer = input.nextInt();
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);
I am writing a code in which a user inputs data as a string and that data must be verified as a valid number. A valid number is anything from 0-100. Then all valid numbers are converted into double numbers.
I am having trouble in how to write the validation part of the code.
Is it suppose to be an if, else statement? And if so how is it suppose to be validated?
My JTable has a row, row number 0, which I always want to be at the top.I tried the following two approaches, both without success:
1- Use a custom table cell renderer for the header, and create a header of two rows. the second row is my JTextField.
Problem: I cannot get the JTextField to function properly. (I've seen examples with a checkbox in the header, but that one just reacts to a click somewhere on the header, my textfield must be editable).
2- Use the first row of the table. This works quite nice. However, I must prevent row 0 to be re-ordered when sorting the table.
I was thinking to add a prefix (either something like "___" or "zzz" depending on current sorting mode), but I do not know which methods to adjust for this exaclty.
Another approach would be to have N textfields above the JTable in some layout (or two JTable's on top of each other).
However, Then I would need to react to the re-ordering and re-sizing of all columns as well, which does not seem easy to me.
I'm trying to build a GUI that must look lik on the image above. There must be three JPanles, the one above, with buttons and combo boxes, must have fixed height and all three must have fixed vertical gaps between them. I'm trying laout after layout but somehow it's not working. I'm allowed to use only standard Swing layouts.
I have a fixed list of 20+ values to be populated in a dropdown. The set of values are always going to remain the same, no future scope of modifications, additions or deletions.
Listing each of them as <option> in JSP is making the page look cluttered. Or is it better reading it as a comma-separated string from a properties file and then iterating to populate the dropdown.
What will be the best approach to populate such a dropdown in JSP?
I want to Write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance.
the Amount is 3,500 the annual rate is 9.9%, the minimum payment is 2% a month. the fixed payment is 150.
By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constant amount that will be paid each month.
The program should print out :
payment information: new balance total ....... current payment due .......
if you make minimum payment (2%) you will pay of in .... months and you Will end up paying an estimated total of $........
if you make the fixed rate payment, you will pay of in .... months and you Will end up paying an estimated total of $........ and you will save $........
I have a TextArea and want to set a linear-gradient as background, which works fine:
.text-area { -fx-background-color: linear-gradient(to bottom, red 0%, blue 100%); }
The problem is that if the TextArea contains much text (and long scrollbars) it is nearly only red. Only if you scroll down to the bottom, it becomes blue.
I want the red-blue gradient always look the same, no matter how much text there is.
In HTML there's something like background-attachment: fixed, which would do the trick, but not so in JavaFX.
Can I achieve it nonetheless. Preferably without any ugly workarounds, like a transparent TextArea within another Pane where the wrapping Pane has the gradient.
I am doing a program where i have to implement a payroll system into a company for hourly, fixed monthly and commission paid workers. I also have to put the method which i did. the problem is I cant tell if my calculation is wrong or if i am missing a codes some where. The output is not giving me the answer that I was at least expected,
I have done a lot researching and have come up with some search with almost the same calculation and I have also asked employees of a company on how they calculated hourly rate, commissions rate and fixed rate for all workers and gotten the same response but for some reason the output is not what it is supposed to output. here is my output.
< un:> <please enter the number of employees to be processed 31> <please enter employee id number 3669> <please enter employee first name>
[Code] ....
I dont know if I am missing some calculation somewhere or codes been researching and bussing my brains to figure out where is the missing codes or calculation.
I am doing a pretty basic program with a fixed origin city and five destination cities. I am having trouble with entering passenger details. This is what I tried, but then I cannot retain all passenger details to print later on in the final ticket.
System.out.println("Enter flight details of child passengers (below 12 years)"); System.out.println("Enter Name"); for(a = 1; a <= cp; ++a) { //cp is number of child passengers, a is loop variable String name = br.readLine(); System.out.println("1. " + name); }
I have to seperate a number 9876 to 6 7 8 9, to 9 8 7 6. I need to know how to sum the digits. I have gotten to this point ::
import java.util.*; public class week4program { static Scanner console = new Scanner (System.in); public static void main(String[] args) { int num1; int digit; int sum = 0;
[code]....
To this point its gives me the seperate integers. OK but how do I get the variable integers into seperate containers and then add them up?My assignment is to do that, and what I have above gets me to where I have seperate digits, but how do I catch them into seperate entities to be added to a sum?
I have it so it gives me the sum of any digit, i just cant figure out how to get only the odd digits to add up. for example if I were to type 123. The odd numbers = 4 but using this program i get 6
class SumOfDigits { public static void main(String args[]) { int sum = 0; System.out.println("Enter multi digit number:");
import java.util.Scanner; public class CubesSum { public static void main (String [] args){ int input; System.out.println("Enter a positive integer:"); Scanner in = new Scanner(System.in); input = in.nextInt();
As you can see I'm using a while loop. For part B which is to modify to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits. So for example, 371 = 3³+7³+1³. How to do it? I need to wrap a for loop around my while loop...