Write A Program To Determine Sum Of Following Harmonic Series For A Given Value Of N
May 9, 2014
write a program to determine the sum of the following harmonic series for a given value of n:1+1/2+1/3+.............................+1/n the value of n should be given interactively through the keyboard.
Here is a simple program on applets that is giving me a bit of headache since it cannot always display the two numbers that it is supposed to: the largest and smallest of the five input integers.....I cannot see where i went wrong, you can always create separately the HTML file to load the applet in an appletviewer of your won size.
* 23.6 (Largest and Smallest) Write an applet that reads five integers, determines which are the largest and smallest integers in the group and prints them. Draw the results on the applet. */ import java.awt.Graphics; import javax.swing.JApplet; import javax.swing.JOptionPane;
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;
I'm trying to change the code on a Fibonacci series program that would allow me to exit the loop early if I exceed a specified number. The user enters any 2 random numbers (which will be the 1st 2 no.'s of the Fibonacci sequence printed to screen) and then continues up to a 'limit' on the number of numbers set in code. Here's the code:
int[] array = new int[limit]; //Define an array whose length is set by an int value for limit!! array[0] = x; //User supplies a int value for x which takes the 1st position in the array!! array[1] = y; //...and an int value for y in the 2nd position!! for (int i = 2; i < limit; i++) //Start from the 3rd position of the array when carrying out calculations!! { array[i] = array[i-1] + array[i-2];
[Code] ....
To exit the code/ 'limit' early if the array prints a number higher than 100, I tried putting a 'while' condition before the last line, as follows:
while (array[i] < 100) System.out.print(array[i] + " ");
Can I even use a 'while' loop within an array, or is there some other way I need to integrate it?
I was tasked with building a program that counts vowels in a phrase or word. I have this working properly, but the problem arises in the next situation. Here is my code:
Scanner userInput = new Scanner(System.in); int userDecision; String Choice; String Phrase; int vowelCount = 0; System.out.println(" This program will count the number of vowels in it.
[Code] ....
As you can see, I used a 'for' statement to declare how long the program should run. However, I need the user to be able to say when it ends. For example, at the end of the program it must say "There are ______ number of vowels in your word. Please press '1' to run the program again, or any other number to exit."
I understand a do-while loop is needed here, but every time I try and create an adequate loop with no logic errors, I either break my existing code, or the program does not work correctly.
Basically, my question is, what is the best way to perform this task? Is a do-while loop necessary, or is there a better way?
You have been given the job of writing a program to assist pilots who fly the Beechcraft Starship-‐‑1 executive aircraft.As with any airplane, it is essential that the pilot know the total weight of the loaded plane at takeoff and its center of gravity. If the plane weighs too much, it won'ʹt be able to lift off. If the center of gravity is outside the limits established for the plane, it might be impossible to control. Your task is to write a program that will determine the total weight and center of gravity of this plane
Inputs: The number of crew members, number of passengers, weight of the forward baggage compartment contents, aft baggage compartment contents weight, and the amount of fuel in gallons are to be accepted as INTEGER values in the order stated. Be sure the input values are within acceptable ranges
Outputs:You must echo the input values, annotated with their appropriate names,calculate and display the total weight, and the center of gravity.
So basically we have this question to do : Write a method dayNumber that determines the number of days in a year up to and including the current day. The method should have three int parameters: year, month, and day. If the value of any parameter is invalid, the method should print a warning message and return the value zero. The table gives some examples of the action of the method. Accept any non-negative year as being valid. You may want to assume the existence of a method numberOfDays that returns the number of days in a given month of a given year. And you should have a method call isLeapYear, if the user enter a year that is a leap year.
This is what I did so far:
class dayMonthYear { public static void main(String[] args) { System.out.println("Enter a year"); int year = In.getInt(); System.out.println("Enter the month for '1' to be January - '12' to be december");
[Code] ....
It works and compiles but my problem is that: let say I enter "12" for December and December has 31 days, so what my program will do since December has 31 days, it thinks each month has 31 days and add them up which will give me 372 when it's suppose to give me 365. How do I make it that it won't do that and that it will work if the year is a leap year too.
I am trying to write a program that basically determines the max amount of units sold and displays it in a dialog box. Also, the program will display the winning sales associate out of 10. I have wrote the program successfully so far and I can see the maximum number of units sold displayed in the dialog box, but I cannot seem to link the winning sales person.
Here is the code I have typed so far.
//Program to find maximum of three number
import javax.swing.JOptionPane; import java.util.Scanner; public class Sales { public static void main (String[] args) { //Declare variables int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10; int large; int winner;
My program successfully reads a file, reports back what it finds and creates an output file. However, I cannot get it to write to the output file, it is always blank!
Here's my code:
import java.util.Scanner; import java.io.*; public class Ex19 { public static void main (String [] args) { //Variables
I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:
Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java public class SumofTwoNumbs { ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
and here: is my code:
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** // This program has variable of several of the integer types. public class SumofTwoNumbs { public static void main(String[] args) {
Write a program called GeometricMean that prompts the user to
1.Enter the number of values (total number of instances) that should be processed
2.A set of values to be processed (in a while loop)and then calculate the geometric mean of the values entered. You should use a while loop to perform the multiplication part of the calculating the geometric mean. The program should output the initial data and the labeled geometric mean. Consider printf, and DecimalFormat.
My Program:
import java.util.Scanner; public class GeometricMean{ public static void main(String[] args) { Scanner keyboard= new Scanner(System.in);
Write a java program that uses a While loop and persistent output to count down from 33 to 0 by threes, and put each value on a separate line, also do this in for loop.
I'm trying to use graphics for my programs and here I'm trying to write a program that searches through files for text received from a JTextField. However, it does not seem to be working as my message is not displayed when text is found...
I'm rather new to programming and I'm trying to make a gui program that will allow the user to create text files. They will be prompted to enter what they'd like to save their file as and then they will be allowed to input text to that file . They will also be allowed to open their files to modify or view its contents. So to start things off, I'm making a prototype if you will.. I've been able to save to a file the problem occurs when I try to read/display it.
Main Class:
public class MainActivity { public static void main(String[] args) { // Access to other classes WriteFile writer = new WriteFile(); ReadFile reader = new ReadFile();
I have a question. How to write a progamme which compensates an average if it is less than a 10/20. I use eclipse and database HSQLDB. I have a table with notes. After the compensates, I must change the note in my database.
Write a program named QuadraticTable.java that takes three double arguments and two int arguments (in that order) from the command line. The three doubles will represent a, b, and c from the quadratic formula.
If the discriminant is non-negative, find and print the solutions to the quadratic equation. (The plus/minus sign in the quadratic formula indicates that you would separately perform both operations). Otherwise print "no real solutions".
Then using the last two int arguments as x_min and x_max, print a table of x and ax
2 + bx + c
values using the a, b, and c read in as command line arguments.
Sample output: (command line arguments were 1 0 2 -3 3)
I am trying to write a program that takes two numbers and multiplies them. I got this idea from this running conversion program
import java.util.Scanner; public class Convert { public static void main (String [] args) { Scanner reader = new Scanner (System.in); double farenheit; double celsius;
[code]...
i am getting a cant find symbol for the output = (alpha*beta) line..Also, am I using the reader object correctly ? hould I create two reader objects as there are 2 inputs needed?
having some trouble doing this. Here are the requirements:
1)Write a program using loop and break to calculate the value of PI. 2)You can use the following equation to calculate PI. PI=4/1-4/3+4/5-4/7+4/9-4/11+4/13 etc.. The program shouldn't loop until the criteria is satisfied. 3)The criteria is the value of PI you get is very close to the “real” value (3.1415926), meaning that their difference should be smaller than a very small numeric number, e.g., 0.0001). 4)The control structures you may need for this program are loop, if-else, and unlabeled break. 5)The output should have the format: for each iteration, it has iteration number and the corresponding value of PI until that iteration. The last line would be the final value of PI.
Here is my code so far:
package ids; public class IDS { public static void main(String[] args) { double pi = 0; for(int i=1; i<=100000; i++){ if ((i%2)==0){ pi+=(4/(2*i-1));
I want an app that I can use to save the name, address, item sold, subject discussed and date that I visited someone - in a job similar to a sales rep. I would like to be able to choose how to sort the info so that if I sort by date I can see who hasn't been visited for the longest and start there. If I think of someone's name then of course I want to sort by name.
One of my friends says he works with "php"[? I'm still learning these terms] and everything happens online. I would like it to be an android app so it can be done without an internet connection ....
Note: use for loop and printf() to format your output
public class MilesandKilometers { public static void main(String[] args) { System.out.println("Miles Kilometers"); int miles = 1 ; for (int i = 1; i <= 10; miles++, i++) { System.out.println(miles + " " + miles * 1.609); } } }
how to make it like the instruction said " use for loop and printf() to format your output".
I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:
insert "}" to complete StatementKALENDER_3.java insert "}" to complete BlockKALENDER_3.java
The code:
import java.util.*; import java.util.Scanner; public class KALENDER_3 } public static void main(String[] args){ Scanner scanner = new Scanner (System.in); System.out.print("Skriv ett manadsnummer: ");
[code].....
I think I have just forgot to put in a few { } symbols, maybe an open loop?