How To Create A Mathematical Sequence
Sep 17, 2014
I want to declare integers, while the program is running.
I run the program and then I give it via System.in.println an integer and repeat this as long as I want. I want the program to give those integers a name of a certain type for, for example a(i) or a[i], dunno, (it should be handy) and then a(i) represents the the i'th integer I gave the program. My idea is then that I can use those elements by their name just like, if I had declared them in the first place. For example add two integers together. For example I defined a method add+, which waits for 2 integer and then adds them. For example I write:
add
a(2)
a(47)
(then I would get here the result.)
However I don't know, how to let the program count the number of inputs or how to let it declare and use variables.
View Replies
ADVERTISEMENT
Sep 17, 2014
I want to declare integers, while the program is running.
I run the program and then I give it via System.in.println an integer and repeat this as long as I want. I want the program to give those integers a name of a certain type for, for example a(i) or a[i], dunno, (it should be handy) and then a(i) represents the the i'th integer I gave the program. My idea is then that I can use those elements by their name just like, if I had declared them in the first place. For example add two integers together. For example I defined a method add+, which waits for 2 integer and then adds them. For example I write:
add
a(2)
a(47)
(then I would get here the result.)
I don't think implementing the add function is difficult. However I don't know, how to let the program count the number of inputs or how to let it declare and use variables.
View Replies
View Related
Nov 14, 2014
class GVector {
// TODO: declare a private array to save the vector coordinates
// Creates a mathematical vector of d dimensions, initialized at 0
public GVector(int d) {
// TODO: implementation
[Code] ....
I'm confused with what type of array I need to use to save the vector coordinates and what to put in Gvector. Is it a constructor?
View Replies
View Related
Nov 12, 2014
My code complies but it won't run and I'm not sure why. ArrayIndexOutOfBoundsException.
I'm trying to create an array that produces the Triangular number sequence:1, 3, 6, 10, 15, 21, 28, 36, 45, ...
Attached image(s)
View Replies
View Related
Mar 3, 2015
I am trying to create a basic graphical user interface for sequence translation (including a JTextField for the description of a sequence and status of function button pressed e.g. “simple” translation and input and output TextFields). This involves a number of different class files. I cannot get my user interface to do what I want and I think I have problems with my "actionPerformed" method. How the code should be linked together?
public void actionPerformed(ActionEvent event) {
try {
// Get the description, content and result
String d = tool.getDescription();
String input = tool.getInputText();
Stringr = translation.getResult();
[code]....
View Replies
View Related
Jan 28, 2015
byte a1 = 0;
byte a2 = 4
byte a3 = 4;
//below statement gives a compilation error
a1 = a2 + a3;
//below line compiles fine.
a1 = 4 + 4;
View Replies
View Related
Apr 20, 2014
How to convert the equation below for bigDecimal objects. I have already tried this, and this and the output is really weird once I call the method. The first block of code is what I'm trying to convert into BigDecimal arithmetic.
public static double calculateFutureValue(double monthlyInvestment,
double monthlyInterestRate, int months) {
double futureValue = 0;
for (int i = 1; i <= months; i++) {
[Code] ....
My attempt at this is as follows:
public static BigDecimal calculateFutureValue(double monthlyInvestment,
double monthlyInterestRate, int months) {
BigDecimal futureValue = new BigDecimal(0.0);
BigDecimal montlyInvestmentDecimal = new BigDecimal(monthlyInvestment);
[Code] ....
Output:
Welcome to the Future Value Calculator
DATA ENTRY
Enter monthly investment: 1
Enter yearly interest rate: .01
Enter number of years: 3
Month: 1 FutureValue: 0E-66
Month: 2 FutureValue: 0E-132
Month: 3 FutureValue: 0E-198
Month: 4 FutureValue: 0E-264
Month: 5 FutureValue: 0E-330
[Code] ....
FORMATTED RESULTS
Monthly investment: $1.00
Yearly interest rate: 0.0%
Number of years: 3
Future value: 0E-2376
Continue? (y/n):
So clearly this still isn't working.
View Replies
View Related
May 28, 2014
I understand how mixing expressions of different data types can result in an error if the assigned variable is not the same data type. But I don't understand how the below causes an error:
short totalPay, basePay = 500, bonus = 1000;
totalPay = basePay + bonus; // This causes the error
500 + 1000 = 1500. 1500 falls within the short parameters. If basePay, bonus, and totalPay are all short, as well as the resulting equation, how is this erroring?
View Replies
View Related
Jan 29, 2015
This first part of code is my HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8">
<link href="jquery/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
[Code] .....
View Replies
View Related
Feb 1, 2014
Using exp4j which is a mathematical parser twice in one routine (or separated) in Eclipse and only the size2 is calculated when app is run in eclipse.
private void calculate size(){
String s1 = size.getText().toString();
String s2 = size2.getText().toString();
try {
Calculable result= new ExpressionBuilder(s1).build();
size1.setText(Double.toString(result.calculate())) ;
[Code] .....
View Replies
View Related
May 3, 2015
Here's my code:
System.out.println((3 / 1.5) + 42(3 + 3));
I don't understand what I'm doing wrong. I'm receiving these errors:
PrintFunction.java:8: error: ')' expected
System.out.println((3 / 1.5) + 42(3 + 3));
^
PrintFunction.java:8: error: not a statement
System.out.println((3 / 1.5) + 42(3 + 3));
^
PrintFunction.java:8: error: ';' expected
System.out.println((3 / 1.5) + 42(3 + 3));
I'm using Sublime Text and JDK 8.
View Replies
View Related
Feb 16, 2015
I need to write a Java program to perform a mathematical calculation between two numbers entered by the user. User has to choose the mathematical operation and input it and then when the user enters 2 numbers, he gets the answer. When user enters any other character other than *, /, + and - he should be able to exit. Perform calculation between numbers should be until user decided to exit from the program. My code is below, calculation part goes well, but can't get it exit when user enter any other character.. How to fix it?
import java.io.*;
public class q11
{
public static void main(String[]args)throws IOException
{
InputStreamReader ISR=new InputStreamReader(System.in);
BufferedReader BR=new BufferedReader(ISR);
while(true){
System.out.println("Enter..");
System.out.println("* : For multiplication");
[Code]...
View Replies
View Related
May 10, 2015
I am trying to write a java program that prints out the number that is the mathematical constant e. As you input a number, the larger it gets , the closer it comes to 2.71828 . Here is my code:
//taylor series that prints out e^1=1+1/1!+1/2!+1/3!+.....
import java.util.Scanner;
public class taylor_1
{
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int factorial =1;
[Code] .....
Here is the output of my code:
enter n
9
Taylor series is 9.0
View Replies
View Related
Aug 6, 2014
How I'm supposed to write out the statement.
I am fairly certain that I should be making variable "b" and "c" a float. But beyond that I'm confused.
uploadfromtaptalk1407333378833.jpg
View Replies
View Related
Mar 28, 2014
I know my problem is my lack of understanding of OOP but I have searched for a solution and can't even seem to get close.This is a very simplified version of what I will need to do. I have a button and six textboxes. When the button is pressed I want to take the text from textbox6 and place it in textbox1, textbox2, textbox3, textbox4, and textbox5.
I need sometthing better then this brut force method.Java Code:
package textboxes;
public class TextBoxesGUI extends javax.swing.JFrame {
public String NewText;
public TextBoxesGUI() {
initComponents();
[code]....
View Replies
View Related
Jun 12, 2014
I what to check if value is not equal to CharSequence value
I try this but getting error:
Java Code:
private CharSequence testvalue = "";
if (!isEqualTo("BCDEF".contains(testvalue))){
}
public boolean isEqualTo(String s_src, String s_compareTo) {
boolean flag = false;
[Code] .....
View Replies
View Related
Mar 23, 2014
Fibonacci Sequence Code:
public class FibSeqByIanNeumann {
public static void main(String[] args) {
Scanner get = new Scanner(System.in);
int ctr, num1, num2, fib, maxTimes;
System.out.print("How many sequences do you want?: ");
maxTimes = get.nextInt(); //inputs the maxium limit of the fib sequence
[code]....
how to do a simple YES/NO Loop so I can try to have it work on my code if I want to try to do the Fibonacci Sequence again.Now I think it might have something to do with a do/while loop.
View Replies
View Related
Jan 6, 2014
Jdeveloper 11.1.1.7.0
Currently I am having an arrayList which consits of the yearweekno.
Example: 201303, 201402, 201401,201352,201351,201350,201349.
which means 01, 02,52,....48 are the weeknumbers.
No my question is if I have today's date i.e new java.util.Date...i.e week 01.
How do I arrange the ArrayList as below
201403 201402 201401 201352 201351 201350 201349
That is if current yearweek is 201401 then display should be as above(current week+2, current week, currentweek -4).
View Replies
View Related
Oct 26, 2014
From a given array of positive and negative numbers, I have to find the longest SUB-Array which represents a Zig-Zag sequence...
A Zig-Zag sequence means that one number is possitive, the next one negative, the next one possitive, and so on and so on...
Like this: -1, 4, -5, 6, -9, 2, -9 etc....
So that means, if the array looks like this:
1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3
the longest sub-array which fulfills the requirement is (the part in bold):
1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3
and I only need it's length, which in this case is: 8
View Replies
View Related
Jan 30, 2015
I'm trying to figure out how to print the Major Scale of any give note in music. It works as follows:
There are 12 notes and each note is assigned a number
C = 0, C# = 1, D = 2, D# = 3, E = 4, F = 5, F# = 6, G = 7, G# = 8, A = 9, Bb = 10, B = 11.
After picking a random note, say F, the idea is to add the following sequence to move through the scale:
0, +2, +2, +1, +2, +2, +2, +1.
So, with F being 5, we move through the scale as 5, 7, 9, 10, 0, 2, 4, 5.
The theory is unimportant but, as you can see, the sequence loops back on itself, rather than continue past 11. This is where I'm stuck, though. I'm not clear on how to loop my numbers around in code. I'll show my attempt here:
public static void main(String[] scale) {
majorScaleOf(0); //0 represents C!!
majorScaleOf(5); //5 represents F!!
majorScaleOf(10); //Bb = B flat!!
[Code] ....
For the sake of simplicity I haven't shown the entire script of 'if' statements, but you get the idea.
The print out reads as:
0, 2, 4 (For C)
5, 7, 9 (For F)
10 (For Bb)
The last line demonstrates the problem, as I need it read as 10, 0, 2.
I've tried different approaches, but wanted to convey the basic problem with this post.
View Replies
View Related
Feb 17, 2014
Whats the best way to implement an error catching sequence.I was developing a program to write to a . csv file. and this is one of the methods in it and how I thought Try/ Catch should be implemented. So I have three different possibilities. Another auxiliary class with some constants:
Java Code:
public class Constants {
/**
* Constant name of the file.
*/
public static final String fileName= "inventory.csv";
[code]....
View Replies
View Related
Feb 12, 2014
public class Fibonacci {
public static void main(String[] args) {
int[] numbers;
numbers = new int[20];
numbers[0] = 0;
numbers[1] = 1;
System.out.println("
[Code] ....
I wrote this program for my Java class to print out the first 20 numbers of the Fibonacci series. My assignment then tells me to Rewrite your program using dynamic array. I'm not sure how to do this.
View Replies
View Related
Apr 15, 2014
I am attempting a programming exercise to display the values in the Fibonacci sequence from F0 to F15. I understand the concept, but, for some reason my equation is simply creating a resulting string of numbers that simply increase by 2's. As, I know it is supposed to be the sum of the previous F and the F that precedes that one to total the new F number. It seems so simple yet I seem to be far off. As usual, I have worked my code for your review.
/*
* This program calculates the "Fibonacci sequence."
* A "sentinel" is used to limit the extent the calculation.
*/
import acm.program.*;
public class bookFibonacciTest2a extends ConsoleProgram {
/* Specifies the limit value of the calculations */
private static final int SENTINEL = 16;
public void run() {
println ("This program display Fibonacci sequence numbers 0 - 15.");
[Code] .....
View Replies
View Related
Oct 30, 2014
I have to find where in the fibonacci sequence a at number belongs, using a if or while loop.
Example
>55 is a Fibonacci number whose order in the sequence is 11
>35 is not a Fibonacci number. However, it lies between Fibonacci numbers 34 (order: 10) and 55 (order: 11)
import java.util.Scanner;
public class While {
public static void main(String[] args) {
System.out.println("Welcome to the Fibonacci Sequence Detector");
Scanner in = new Scanner(System.in);
[Code] .....
View Replies
View Related
Apr 1, 2014
So I have one set of If Else If statements. My program calculates just the first comboBox. It is retrieving all the values from the other comboBoxes but I do not understand where to place the other If statement structure so I can calculate the other values I have set for the other objects. I would not like to use a different class for each and I know I have my calculations done right below my current if statement. Could it be left there and where shall I place the other if statements so they get read by my arithmetic sequence?
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource() ;
int deckSiz = (int) Decks.getSelectedIndex() ;
int wheelSiz = (int)Wheels.getSelectedIndex();
[code]....
View Replies
View Related
Sep 3, 2014
Consider the sequence of digits from 1 through N (N<=9) in increasing order: 1 2 3 4 N
Insert either a +(for addition) or a - (for subtraction) between each of the digits so that the resultant sum is zero. Print all possible combinations that sum to zero.
Example: Enter a number: 7
1+2-3+4-5-6+7=0
1+2-3-4+5+6-7=0
1-2+3+4-5+6-7=0
1-2-3-4-5+6+7=0
View Replies
View Related