469,904 Members | 2,103 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

Need help cannot figure out where I made the error.

Need help cannot figure out where I made the error.
--------------------------------------------------------------------------------

Can someone view what I have, I need help I cannot figure out where I went wrong.

Thanks


/* Jose N. Ramirez
CS151

This program will key you a brief overview of how

Java uses the new Scanner class to accept integers

entered then adds them by the user via the keyboard and assigns

them to a primitive variable. */





import java.util.*;



public class Math223

{





public static void main( String args[] )

{



int number1; // first number to add

int number2; // second number to add

int number3; // third number to subtract





Scanner scannerObject =new Scanner(System.in);



System.out.println("This program will add two integers then subtract the third");

System.out.println("together and output the product.\n");



System.out.println("Enter the first integer using the keyboard");



/* This statement assigns the first integer entered by the

user to the scannerObject named number1 */

number1=scannerObject.nextInt();





System.out.println("\n");

System.out.println("Now enter the second integer.");



/* This statement assigns the second integer entered by the

user to the scannerObject named number2 */

number2=scannerObject.nextInt();



System.out.println("You entered "+number1+" and "+number2+" and "-number3" ");

System.out.println("\n");



/*This statement multiplies the integers entered by the

user together and assigns the result to primitve variable

named product.*/

int product = number1 + number2 - number3;





/*This statement outputs the numbers the user enters and

the results obtained by adding them together then subtracting the third number.*/



System.out.println("The product of "+number1+" + "+number2+" - "-number3" ");

System.out.println(" is "+product+"\n\n\n");







} // end method main



} // end of Math223 class
Nov 15 '06 #1
2 1509
r035198x
13,262 8TB
Need help cannot figure out where I made the error.
--------------------------------------------------------------------------------

Can someone view what I have, I need help I cannot figure out where I went wrong.

Thanks


/* Jose N. Ramirez
CS151

This program will key you a brief overview of how

Java uses the new Scanner class to accept integers

entered then adds them by the user via the keyboard and assigns

them to a primitive variable. */





import java.util.*;



public class Math223

{





public static void main( String args[] )

{



int number1; // first number to add

int number2; // second number to add

int number3; // third number to subtract





Scanner scannerObject =new Scanner(System.in);



System.out.println("This program will add two integers then subtract the third");

System.out.println("together and output the product.\n");



System.out.println("Enter the first integer using the keyboard");



/* This statement assigns the first integer entered by the

user to the scannerObject named number1 */

number1=scannerObject.nextInt();





System.out.println("\n");

System.out.println("Now enter the second integer.");



/* This statement assigns the second integer entered by the

user to the scannerObject named number2 */

number2=scannerObject.nextInt();



System.out.println("You entered "+number1+" and "+number2+" and "-number3" ");

System.out.println("\n");



/*This statement multiplies the integers entered by the

user together and assigns the result to primitve variable

named product.*/

int product = number1 + number2 - number3;





/*This statement outputs the numbers the user enters and

the results obtained by adding them together then subtracting the third number.*/



System.out.println("The product of "+number1+" + "+number2+" - "-number3" ");

System.out.println(" is "+product+"\n\n\n");







} // end method main



} // end of Math223 class
You forgot to read in the third number.
Nov 15 '06 #2
try this
Expand|Select|Wrap|Line Numbers
  1.     package com.test;
  2.  
  3.     /* Jose N. Ramirez
  4.      CS151
  5.  
  6.      This program will key you a brief overview of how
  7.  
  8.      Java uses the new Scanner class to accept integers
  9.  
  10.      entered then adds them by the user via the keyboard and assigns
  11.  
  12.      them to a primitive variable. */
  13.  
  14.     import java.util.*;
  15.  
  16.     public class Math223
  17.  
  18.     {
  19.  
  20.     public static void main( String args[] )
  21.  
  22.     {
  23.  
  24.  
  25.  
  26.     int number1; // first number to add
  27.  
  28.     int number2; // second number to add
  29.  
  30.     int number3; // third number to subtract
  31.  
  32.  
  33.  
  34.  
  35.  
  36.     Scanner scannerObject =new Scanner(System.in);
  37.  
  38.  
  39.  
  40.     System.out.println("This program will add two integers then subtract the third");
  41.  
  42.     System.out.println("together and output the product.\n");
  43.  
  44.  
  45.  
  46.     System.out.println("Enter the first integer using the keyboard");
  47.  
  48.  
  49.  
  50.     /* This statement assigns the first integer entered by the
  51.  
  52.     user to the scannerObject named number1 */
  53.  
  54.     number1=scannerObject.nextInt();
  55.  
  56.  
  57.  
  58.  
  59.  
  60.     System.out.println("\n");
  61.  
  62.     System.out.println("Now enter the second integer.");
  63.  
  64.  
  65.  
  66.     /* This statement assigns the second integer entered by the
  67.  
  68.     user to the scannerObject named number2 */
  69.  
  70.     number2=scannerObject.nextInt();
  71.  
  72.  
  73.  
  74.     System.out.println("You entered "+number1+" and "+number2+" and "+number3);
  75.  
  76.     System.out.println("\n");
  77.  
  78.  
  79.  
  80.     /*This statement multiplies the integers entered by the
  81.  
  82.     user together and assigns the result to primitve variable
  83.  
  84.     named product.*/
  85.  
  86.     int product = number1 + number2 - number3;
  87.  
  88.  
  89.  
  90.  
  91.  
  92.     /*This statement outputs the numbers the user enters and
  93.  
  94.     the results obtained by adding them together then subtracting the third number.*/
  95.  
  96.  
  97.  
  98.     System.out.println("The product of "+number1+" + "+number2+" - "+number3);
  99.  
  100.     System.out.println(" is "+product+"\n\n\n");
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.     }
  109.     }
  110.  
-number3" " was used at two places and } (at end)was missing
try eclipse IDE these errors wont be any problem to find
Nov 15 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Kyle Goetz | last post: by
7 posts views Thread by George Jordanov Ivanov | last post: by
9 posts views Thread by pic078 via AccessMonster.com | last post: by
10 posts views Thread by =?Utf-8?B?UmF2aSBTaGFua2Fy?= | last post: by
5 posts views Thread by Chuck Anderson | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.