Anthony
Anthony

Reputation: 3

How do I get my java program to output the answer?

I'm new to java and my class has a homework assignment that I need a little help on. I finished everything except for the output, I can't seem to get the program to produce the answer.

    import java.util.Scanner;
    public class HomeworkScanner
   {

     public static void main(String args[])
     {

            int x, y, z, a, result;
            Scanner Keyboard;
            Keyboard = new Scanner(System.in);
            System.out.println("a = ( x + y ) * z");
            System.out.println("Enter first number for x:");
            x = Keyboard.nextInt(); //
            System.out.println("Enter second number for y:");
            y = Keyboard.nextInt(); //
            System.out.println("Enter third number for z:");
            z = Keyboard.nextInt(); //
            result=a=( x + y ) * z;
         }
    }

Upvotes: 0

Views: 68

Answers (3)

Paras Mittal
Paras Mittal

Reputation: 1149

import java.util.Scanner;
public class HomeworkScanner
{

 public static void main(String args[])
 {

        int x, y, z, a, result;
        Scanner Keyboard;
        Keyboard = new Scanner(System.in);
        System.out.println("a = ( x + y ) * z");
        System.out.println("Enter first number for x:");
        x = Keyboard.nextInt(); //
        System.out.println("Enter second number for y:");
        y = Keyboard.nextInt(); //
        System.out.println("Enter third number for z:");
        z = Keyboard.nextInt(); //
        result=a=( x + y ) * z;
        System.out.println("result is :"+result);
     }
}

Upvotes: 1

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35577

You can just use System.out.println("Result: "+result); to print your result in the console.

Upvotes: 0

Le Ish Man
Le Ish Man

Reputation: 461

I'm assuming you want the format "Result = a" which would be

System.out.println("Result = " + result);

Or you could use a since you set them to the same value

Upvotes: 1

Related Questions