//**************************************...
// Tara D
// CS1 -- 10:00 -- Pgm #2
//
// Program Integers: Get five decimal numbers and convert
// to integers. Add five integers to get sum. Then take
// sum divde by five to get average.
//
//************************************...
//
// prompt user for five decimal numbers = decNum
// print five decimal numbers = decNum
// convert decimal number to nearest integer if decNum <.5
// decNum == something
// else if decNum >.4
// decNum == something
// add five integers
// print sum and average of five integers
//
//
//************************************...
import java.util.*;
public class MySecondJavaProgram
{
static Scanner console = new Scanner(System.in);
public static void main (String[] args)
{
//declare variables
double num1, num2, num3, num4, num5;
int sum, average;
//statements
System.out.print("Enter a decimal number:");
num1 = console.nextInt();
System.out.print("Enter a decimal number:");
num2 = console.nextInt();
System.out.print("Enter a second decimal number:");
num3 = console.nextInt();
System.out.print("Enter a thrid decimal number:");
num4 = console.nextInt();
System.out.print("Enter a fourth decimal number:");
num5 = console.nextInt();
System.out.println(num1, num2, num3, num4, num5);
//some statement to make decimal to nearest integer
sum = num1 + num2 + num3 + num4 + num5;
System.out.println("The sum is " + sum);
average =(num1 + num2 + num3 + num4 +num5) / 3;
System.out.println("The product is " + product + "\nThe average is " + average);
}//static close
} // class close
----jGRASP exec: javac -g F:\Java\Chapter 2\MySecondJavaProgram.java
MySecondJavaProgram.java:47: cannot find symbol
symbol : method println(double,double,double,double,doub...
location: class java.io.PrintStream
System.out.println(num1, num2, num3, num4, num5);
^
MySecondJavaProgram.java:51: possible loss of precision
found : double
required: int
sum = num1 + num2 + num3 + num4 + num5;
^
MySecondJavaProgram.java:54: possible loss of precision
found : double
required: int
average =(num1 + num2 + num3 + num4 +num5) / 3;
^
MySecondJavaProgram.java:55: cannot find symbol
symbol : variable product
location: class MySecondJavaProgram
System.out.println("The product is " + product + "\nThe average is " + average);
^
4 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
----jGRASP exec: java MySecondJavaProgram
Enter a decimal number:2.2
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:...
at java.util.Scanner.next(Scanner.java:1461...
at java.util.Scanner.nextInt(Scanner.java:2...
at java.util.Scanner.nextInt(Scanner.java:2...
at MySecondJavaProgram.main(MySecondJavaPro...
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Tags: