Jump to content
Fórum Script Brasil
  • 0

Dificuldade em exercício de java

Luiz Eduardo Monteiro


O exercício diz para criar um programa que leia um numero n e fazer a soma de 1/1 até 1/n, por exemplo, se o numero lido for 5, é pra fazer a soma de  1 + 1/2 + 1/3 + 1/4 + 1/5

O erro que da é: Type mismatch: cannot convert from int to boolean


import java.util.Scanner;
public class JavaBasico {
    public static void main(String[] args) {
        Scanner ler = new Scanner(System.in);
        double total = 0;
        System.out.println("Digite um numero");
        int n = ler.nextInt();
        for(int cont=1cont=ncont++){
        double s = 1/cont;
        total = s + total;       
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

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

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...