1. Generalized harmonic numbers. Write a program GeneralizedHarmonic.java that takes two integer command-line arguments n and r and uses a for loop to compute the nh generalized harmonic number of order r, which is defined by the following formula:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

My code keeps giving me an answer of 1.  If i set the values manually it gives a correct answer so the math portion is correct but when i add a command line it always gives value of 1 please help

Flle
Edit view Code
Bulld
RU
LIFT
Help
Wéék 2 - GeherallzedHarmoniC.java
O Project v
GeneralizedHarmonic.java X
v Week 2 C:\Users\Tyler_0qxkiq5\Desktop\Week 2
7
int n = Integer.parseInt(args[0]);
src
8
int r =
Integer.parseInt(args[1]);
GeneralizedHarmonic
nli External Libraries
9
Scratches and Consoles
10
//Looping
11
for (int i = 1; i <= n; i++) {
12
//Computing the sum
13
sm += 1.0 /Math.pow(i,r);
14
}
15
// print the nth harmonic number
16
System.out.println(sum);
17
18
}
19
}
20
Run:
GeneralizedHarmonic X
"C:\Program Files\Adopt0penJDK\jdk-11.0.11.9-hotspot\bin\java.exe" "-javaagent:C:\Program Files (x86)\JetBrains\IntelliJ IDEA
1.0
Process finished with exit code 0
|
IG RI D
Transcribed Image Text:Flle Edit view Code Bulld RU LIFT Help Wéék 2 - GeherallzedHarmoniC.java O Project v GeneralizedHarmonic.java X v Week 2 C:\Users\Tyler_0qxkiq5\Desktop\Week 2 7 int n = Integer.parseInt(args[0]); src 8 int r = Integer.parseInt(args[1]); GeneralizedHarmonic nli External Libraries 9 Scratches and Consoles 10 //Looping 11 for (int i = 1; i <= n; i++) { 12 //Computing the sum 13 sm += 1.0 /Math.pow(i,r); 14 } 15 // print the nth harmonic number 16 System.out.println(sum); 17 18 } 19 } 20 Run: GeneralizedHarmonic X "C:\Program Files\Adopt0penJDK\jdk-11.0.11.9-hotspot\bin\java.exe" "-javaagent:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 1.0 Process finished with exit code 0 | IG RI D
CONDITIONALS
G LOOPS
LOOPS AND CONDITIONALS
FAQ O
Spec E
Project D
Submit co
1. Generalized harmonic numbers. Write a program GeneralizedHarmonic.java that takes two integer command-line arguments n and r and uses a for loop to compute
the n'h generalized harmonic number of order r, which is defined by the following formula:
1
1
1
H(n, r)
1"
2"
n"
1
For example, H(3, 2)
1²
49
- 1.361111.
36
1
22
32
~/Desktop/loops> java GeneralizedHarmonic 1 1
1.0
~/Desktop/loops> java GeneralizedHarmonic 2 1
1.5
~/Desktop/loops> java GeneralizedHarmonic 3 1
1.8333333333333333
~/Desktop/loops> java GeneralizedHarmonic 1 2
1.0
~/Desktop/loops> java GeneralizedHarmonic 2 2
1.25
~/Desktop/loops> java GeneralizedHarmonic 3 2
1.3611111111111112
Note: you may assume that n is a positive integer.
Transcribed Image Text:CONDITIONALS G LOOPS LOOPS AND CONDITIONALS FAQ O Spec E Project D Submit co 1. Generalized harmonic numbers. Write a program GeneralizedHarmonic.java that takes two integer command-line arguments n and r and uses a for loop to compute the n'h generalized harmonic number of order r, which is defined by the following formula: 1 1 1 H(n, r) 1" 2" n" 1 For example, H(3, 2) 1² 49 - 1.361111. 36 1 22 32 ~/Desktop/loops> java GeneralizedHarmonic 1 1 1.0 ~/Desktop/loops> java GeneralizedHarmonic 2 1 1.5 ~/Desktop/loops> java GeneralizedHarmonic 3 1 1.8333333333333333 ~/Desktop/loops> java GeneralizedHarmonic 1 2 1.0 ~/Desktop/loops> java GeneralizedHarmonic 2 2 1.25 ~/Desktop/loops> java GeneralizedHarmonic 3 2 1.3611111111111112 Note: you may assume that n is a positive integer.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
InputStream
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education