Help with this JAVA Problem [closed]

-1
package problema.pkg7.pkg2;
import java.util.Scanner;


public class Problema72 {


    public static void main(String[] args) {
              Scanner sc=new Scanner(System.in);
        Scanner input = new Scanner (System.in);

        int num1;
        int num2;     
        int num3;
        int producto;
        int suma;

        System.out.print("Ingrese el Primer Valor");
        num1 = input.nextInt ();

        System.out.print("Ingrese el Segundo Valor");
        num2 = input.nextInt ();

        System.out.print("Ingrese el Tercer Valor");
        num3 = input.nextInt ();

        suma = num1 + num2 + num3;
        producto = num1 * num2 * num3;

        int n= sc.nextInt();
      if(n==0){
              System.out.println("El numero "+n+" es positivo");
          }else{
          System.out.println("El numero "+n+" es negativo");
          }



      System.out.print("La Suma de los 3 Valores Es" +suma);

      System.out.print("El Resultado De Los 3 Productos Es");
    
asked by DOOM 23.08.2017 в 11:26
source

1 answer

2

In the code there are a few syntax errors as well as an understanding of what you have been asked for. Here I leave a modification of your code:

package problema.pkg7.pkg2;
import java.util.Scanner;


public class Problema72 {


    public static void main(String[] args) {
              Scanner sc=new Scanner(System.in);
        Scanner input = new Scanner (System.in);

        int num1;
        int num2;     
        int num3;
        int producto;
        int suma;

        System.out.print("Ingrese el Primer Valor");
        num1 = input.nextInt ();

        System.out.print("Ingrese el Segundo Valor");
        num2 = input.nextInt ();

        System.out.print("Ingrese el Tercer Valor");
        num3 = input.nextInt ();
       // ANTES DE REALIZAR LA SUMA O EL PRODUCTO COMPROBAR SI ES NEGATIVO
        if (num1 <0){
         // El valor es negativo
         producto = num1 * num2 * num3;    
         System.out.print("El Resultado De Los 3 Productos Es: "+ producto);
        } else{
         // El valor es positivo
         suma = num1 + num2 + num3;                 
         System.out.print("La Suma de los 3 Valores Es: " +suma);
        } 

This part of your code I do not know what you want to do:

int n= sc.nextInt(); // EL PRIMER NÚMERO QUE INSERTAS ES LA VARIABLE num1
      if(n==0){ // SI N == 0 ES POSITIVO, PERO SI ES MAYOR A 0 NO?
              System.out.println("El numero "+n+" es positivo");
          }else{ // TODO LO QUE NO SEA IGUAL A 0 ES NEGATIVO?
          System.out.println("El numero "+n+" es negativo");
          } 

In the comments I have made, I show you the confusion of if , the conditions are:

  • == (Same as)
  • ! = (Other than)
  • < = (Less than or equal to)
  • > = (Greater than or equal to)
  • < (Less than)
  • > (Greater than)
  • answered by 23.08.2017 / 12:01
    source