Soma de dois números. erro

Bom dia, ajuda básica. O que está errado no seguinte código? Netbeans…

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.
    */

/**
*

  • @author luiz_
    */
    public class Soma2Numeros {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      Scanner input = new Scanner (System.in);

      int number1;
      int number2;
      int sum;

      System.out.print ("Enter first integer: ");
      number1 = input.nextInt();
      System.out.print("Enter second integer: ");
      number2 = input.nextInt();
      sum = number1 + number2;

      System.out.printf (“Sum is %d%n”, sum);
      }

}

Erro compilador:

:Erro: Não foi possível localizar nem carregar a classe principal soma.pkg2.numeros.Soma2Numeros
C:\Users\luiz_\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)

Isso é Bug do NetBeans. Tente criar a classe novamente, provavelmente vai dá certo.

ao inves de System.out.printf (“Sum is %d%n”, sum);

mude para System.out.printf ("sum is " + sum);

1 curtida

Ao invés de “enves”, escreva “invés” :wink:

Está correto ele usar o System.out.printf (“Sum is %d%n”, sum);

pq usar essa syntax?? System.out.printf (“Sum is %d%n”, sum); ?

Verifique as aspas duplas nessa linha.

“, ” e " são diferentes, use ".

Pra poder aplicar regras de formatação na própria String.

1 curtida