Перейти к содержимому
View in the app

A better way to browse. Learn more.

Zloplay community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Опубликовано:

First note: Serious answers are mandatory. Else I'll just kick you out.

I've started with Java at school and got a question I seriously don't know how to answer. I need to do the following:

 

"In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Assume that n is an integer variable whose value is some positive integer N. Assume also that hn is a variable whose value is the Nth harmonic number. Write an expression whose value is the (N+1)th harmonic number. "

 

That is.. all I got. I do understand if you start dividing the numbers it should be 1.0/2.0 etc. however, what I really want is just some advice of one of you on how to get the answer here. Well actually if you are bored, just give me the answer. It isn't really included in my text book and I just want to finish this question as it is a few of the final ones I need to finish this week.

 

Thanks in advance,

Featured Replies

Опубликовано:
  • Автор
Using your notation...

hn + ( 1 / (n + 1) )

If you actually need to calculate nh then just use a for loop.

 

Thank you, when I saw your answer I did understand the question alot more. Sounded a bit vague to me first. Had to change it to hn+1.0/(n + 1) before codelab accepted it.

Опубликовано:
Thank you, when I saw your answer I did understand the question alot more. Sounded a bit vague to me first. Had to change it to hn+1.0/(n + 1) before codelab accepted it.

seeing as otherwise ints are being used, and by making one factor a float/double (by adding .0 after it) you basically tell the entire expression to be a floating-point number.

Опубликовано:
  • Автор

Having a new problem here.

 

Question

Write an application that reads values representing a time duration in hours, minutes, and seconds and then prints the equivalent total number of seconds. (For example, 1 hour, 28 minutes, and 42 seconds is equivalent to 5322 seconds.)

 

SPECIFICATION OF PROMPTS, LABELS AND OUTPUT: Your code should use these prompts: "hours: ", "minutes: ", "seconds: ". The prompts should not force the user to type the required input on the next line. After all the inputs, the output should consist of a single line consisting of an integer (the total number of seconds) followed by a space followed by a label for the units: seconds. For example:

hours: 2

minutes: 10

seconds: 7

7807 seconds

 

SPECIFICATION OF NAMES: Your application class should be called Seconds

 

My answer

 

import java.util.Scanner;

public class Seconds {

public static void main (String[] args) {

int hours;

int minutes;

int seconds;

Scanner scan = new Scanner( System.in );

hours = scan.nextInt();

minutes = scan.nextInt();

seconds= scan.nextInt();

System.out.print( "hours: "

+ (3600 * hours) + "minutes: " + (60 * minutes) + "seconds: " + ( seconds ) + (3600 * hours + 60 * minutes + seconds) + " seconds");

 

}

}

 

 

When I submit this code the following error pops up on myprogramminglab: В В В в‡’В В В В В Your standard output is not what was expected.

Expected Output:

 

hours:В¶

minutes:В¶

seconds:В¶

0В§seconds

Actual Output:

 

hours:67;0minutes:В§0seconds:В§00В§secondsВ¶

LEGEND OF SPECIAL SYMBOLS:

Symbol Meaning

В§ Space Char

В¶ Newline (\n)

В¬ Tab (\t)

В» Carriage Return (\r)

 

Any idea what I need to include here? Personally I think the \n but no clue where to add those.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гость
Ответить в тему...

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу

Важная информация

Используя этот сайт, вы соглашаетесь Условия использования.

Account

Navigation

Поиск

Поиск

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.