Hello Everyone,
I am new Java Programming and I am struggling to pass my Java class. I have no idea on how to perform Java but I am trying lol. I am following assignments out of my work book and I have no idea as to what I am doing wrong. For this particular assignment I supposed to:
* Change all variables' data types to double.
* Change the two prompts to request double values
* Change change the two calls to the nextInt() method to nextDouble().
This is the original assignment:
import java.util.Scanner;
public class ArithmeticDemo
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int firstNumber;
int secondNumber;
int sum;
int difference;
int average;
System.out.print("Please enter an integer>> ");
firstNumber = input.nextInt();
System.out.print ("Please enter another integer>> ");
secondNumber = input.nextInt ();
sum = firstNumber + secondNumber;
difference = firstNumber - secondNumber;
average = sum / 2;
System.out.println(firstNumber + " + " + secondNumber + "is" +sum);
System.out.println(firstNumber + " - " + secondNumber + "is" +difference);
System.out.println("The average of " + firstNumber + " and " +secondNumber + "is" +average);
}
}
This is the changes that I have made which are probably wrong:
import java.util.Scanner;
public class ArithmeticDemo2
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int firstNumber;
int secondNumber;
int sum;
int difference;
int average;
System.out.print("Please enter an double>> ");
firstNumber = input.nextDouble();
System.out.print ("Please enter another double>> ");
secondNumber = input.nextDouble();
sum = firstNumber + secondNumber;
difference = firstNumber - secondNumber;
average = sum / 2;
System.out.println(firstNumber + " + " + secondNumber + "is" +sum);
System.out.println(firstNumber + " - " + secondNumber + "is" +difference);
System.out.println("The average of " + firstNumber + " and " +secondNumber + "is" +average);
}
}
This is the error that I am getting:
G:\ArithmeticDemo2.java:16: error: possible loss of precision
firstNumber = input.nextDouble();
^
required: int
found: double
G:\ArithmeticDemo2.java:18: error: possible loss of precision
secondNumber = input.nextDouble();
^
required: int
found: double
2 errors
Tool completed with exit code 1
Can someone please tell me what I did wrong or what I am missing? The work book that is assigned for my class is not helpful at all
Thanks so much!!