I have just started to learn programming in the book I am teaching myself from it said how would you write the following arithmetic expression with it being the quadratic formula but only the plus part of it in the plus or minus..
package javalearning; import java.util.Scanner; public class QuadraticFormula { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter value for B: "); double B = input.nextDouble(); System.out.print("Enter value for A: "); double A = input.nextDouble(); System.out.print("Enter value for C: "); double C = input.nextDouble(); double negativeOfB = -B;
I am not sure how to add all the possibilities of elements in an array and find the greatest sum. I want to do this recursively. I don't need any code. How I would do it.
I wrote this tail recursive function that mirrors the iterative version, except that the loop in the iterative version is replaced by an if statement here and then a recursive call. Is this truly recursive? I have seen the fibo(n-1) + fibo(n - 2) version, but is this also an acceptable recursive solution? Why is it never solved this way?
public class FiboRecursive { public static int fibo (int n) { int sum = 0; int n1 = 1; int n2 = 1; if (n == 1 || n == 2) { sum = 1;
How do i go about developing a simple arithmetic tester program which can be used to support young children improve their arithmetic skill. The program should accepts string data for the player's name and the number of questions they want to try, which will be entered by the user. The program should take in the following inputs from the user:
The name of the player, so that the game can refer to them by name in messages. The name must be between 2 and 20 characters inclusive.
The number of sums that the user wants to attempt. This number must be a whole number, and be between 2 and 50 inclusive.
The program must check that the values entered fall within the valid ranges. The program must also check that no empty strings are entered for names.
Once the player has entered their name and the number of questions they want to attempt, the game begins. The program must generate sums for the player.
The program should generate one question at a time and display the question for the user. The questions must involve two numbers and be either a multiplication, division, subtraction, or addition. For example, the following are all valid questions:
3 * 4 = ? 8 / 2 = ? 7 + 1 = ? 9 - 8 = ?
The first number, second number, and arithmetic operator (multiply, divide, add, subtract) should all be chosen randomly, the program should Generate a new random number for each of the three parts of each sum. this requires you to choose one of the four symbols based on which random number is returned.
A few checks must be carried out before a generated question is displayed to the user. If the question is an addition question, no checks are required. If the question is a multiplication question, no checks are required. However, checks are required for subtraction and division sums.
If the question is a subtraction question, the program must check that the second number is equal to or smaller than the first number. Whilst the second number is larger than the first number, new numbers should be generated.
I'm trying to implement a non-recursive version of the insertion method, but I'm having a bit of trouble. From what I can tell, it's only returning the last two node..
public void insert(Key key, Value val) { root = insert(key, val, root); } private Node insert(Key key, Value val, Node x) { if(x == null) { x = new Node(key, val, 1);
import java.util.*; public class TestArithmetic { public static void main(String [] args) { Scanner console = new Scanner (System.in); System.out.println("Enter First Number"); int x1 = console.nextInt(); System.out.println("Enter Second Number");
This is what I have so far, but I don't know how to continue:
import java.util.Scanner; public class ArithmeticComputation{ public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int num1 = stdin.nextInt();
[Code] ....
I'm looking for a method that allows me to assign char into actual operators, so that I can loop through all the computation.
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();
As one of the methods of my IntTree tree I have to implement a method that multiplies the level number with the sum of the nodes on the current level. So far I have this, and it doesn't work. What I am wondering is am I on the right track at all with the second return statement?
public int depthSum(){ return depthSum(overallRoot); } private int depthSum(IntTreeNode root) { if(root==null) return 0; int level = 0;
The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.
Here is what I have so far:
double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 }; ArrayList<Double> d = new ArrayList<Double>(); ArrayList<Double> e = new ArrayList<Double>(); for ( double x : q ) { d.add( x ); e.add ( new Double ( x ) );
[Code] .....
Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.
2) Specify what arithmetic operators to swap (+, -, /, *)
2) If an arithmetic operator is read (like a + sign etc) then we swap it with its opposite (- for example)
3) Once the swap is complete, the rest of the file stays the same even if more operators are in the file...it is then output to a file (I am going with 1mutation.java)
4) This is where it gets tricky....it then picks up where it left off to finish reading the + operators (or whatever was specified) and repeats steps 2-3 (but the operator that is already swapped gets left as it was / skipped) and the output is saved as 2mutation.java.
The most I have been able to manage is having it changed 1 operator or all of them at once. I deleted a lot of my work to start fresh / master one operator for the time being. Here is what I have:
This is the data file I am using. (see attached) The file should be .java or .cpp but I stuck with .txt for now. How to tackle this? Am I on the right track?
I have written this program but I am seeing error when I compile this program ( javac TestArithmetic.java).
1)TestArithmetic.java:26 cannot find symbol
2)symbol: class Arithmetic
3)location: class TestArithmetic
4) Arithmetic ar = new Arithmetic(x1,x2,x3);
1)TestArithmetic.java:26 cannot find symbol
2)symbol: class Arithmetic
3)location: class TestArithmetic
4) Arithmetic ar = new Arithmetic(x1,x2,x3);
2 errors.
Code :
import java.util.*; class TestArithmetic { public static void main (String[] args){ float number; Scanner console= new Scanner (System.in); System.out.println("Enter first number");
I am new Java Programming and I am struggling to pass my Java class. How to perform Java but I am trying. For this particular assignment I supposed to:
* Change all variables' data types to double. * Change the two prompts to request double values * Change change the two calls to the nextInt() method to nextDouble().
This is the original assignment:
import java.util.Scanner; public class ArithmeticDemo { public static void main(String[] args) { Scanner input= new Scanner(System.in); int firstNumber; int secondNumber; int sum; int difference; int average;
I have a requirement where I have a class as Page which itself contains ArrayList<Page>.Here ArrayList<Page> is nothing but the pages which are accessible from the base Page.I know the depth level ( reading from file) which means how many level I need to go to identify more pages.BUT the problem is how to set the base Page class. I need to set the base Page class but for that I need the objects for the subsequent pages and hence an iterative type of implementation.
I was told to write a method that adds up the sequence of the formula (n/2n+1) eg. 1/3 + 2/5 + 3/7 etc. simple enough i suppose. my method is below
public static double Series(int n){ if (n==0)return 0; else return (n/(n*2+1)) + Series(n - 1); }
However for some reason or another it returns 0 for any number that is put in. I've written it dozens of different ways with no change and i feel like something fairly obvious is being missed on my part. I am honestly intrigued and interested as to why this is happening. i assume it has something to do with the way i put the actual formula in cause if i put anything else in like simply n the recursion would work as expected.
I recently wrote a simple recursive program that chooses K objects out of N (I was asked to use the variables N choose the R, however) total objects. Here is the code:
int n = 0; int r = 0; //the total number of objects defaults to 0 String nChoice = JOptionPane.showInputDialog(null, "How many objects are there to choose from?"); String rChoice = JOptionPane.showInputDialog(null, "How many object are to be chosen from this group?"); try { n = Integer.parseInt(nChoice);
[Code] ....
It works fine, however in my class we were given two different formula to implement into our code. I used the one above, obviously. However, the second formula we were given was:
C(n,R) = n! -------(R!(n-R)!)
I had to get the spacing right.
How do I read this formula? How could it be implemented? What are the benefits (if there are any) from using one method over the other? Which method of calculating N choose K (or, in my case, N choose R) would be more widely accepted?
I'm trying to understand the concept behind this recursive method called rangeSum. This method sums a range of array elements with recursion. I tried summing the elements of 2 through 5, and I tried writing down what actually happens when java executes the program, but what I get when I try to figure it out by paper is different from what netbeans gives me. Here is a snapshot of my scratch work as well as my source code. Netbeans gives me "The sum of elements 2 through 5 is 18" when I try running it but it I get 12 when I do the recursion on paper. I know that the source code is correct because it's out of the book but what am I doing wrong when I try figuring it out by hand?
XML Code:
package recursivecall; import java.util.Scanner; /** * Author: <<Conrado Sanchez>> Date: Task: */ public class RecursiveCall {
I am trying to write a program which asks the user to enter two numbers and then do the arithmetic operation based on user's input . No compiling errors but when I run the program I keep getting "StringIndexOutOfBounds" error .
class arithmetic { public static void main(String[] args){ Scanner in = new Scanner(System.in); int ent1 = 0;