I have an assignment that wants me to write an application that takes 5 numbers from a user. As the user inputs the numbers I have to make them into a double, float, long, int and byte. All I need after this is to output the result of the following calculation and store the result in an int variable.
Calculation to do
Subtract the floatValue from the intValue, then multiply by the doubleValue, then divide by the longValue, then multiply by the byteValue and then divide by 2. I am to store the result in an int variable. I can get the user input but am at a loss as to how to do the calculation and store the result in an int variable. Can someone out in cyberworld help? Thanks to anyone who responds.
CODE
import java.util.*;
public class TestNumbers
{
public static void main(String args[])
{
Scanner input = new Scanner(System. in);
int result;
System.out.prin tln("Enter a number:");
double num1 = input.nextDoubl e();
System.out.prin tln();
System.out.prin tln("Enter second number:");
float num2 = input.nextFloat ();
System.out.prin tln();
System.out.prin tln("Enter third number:");
long num3 = input.nextLong( );
System.out.prin tln();
System.out.prin tln("Enter fourth number:");
int num4 = input.nextInt() ;
System.out.prin tln();
System.out.prin tln("Enter fifth number:");
byte num5 = input.nextByte( );
System.out.prin tln();
}
}
Calculation to do
Subtract the floatValue from the intValue, then multiply by the doubleValue, then divide by the longValue, then multiply by the byteValue and then divide by 2. I am to store the result in an int variable. I can get the user input but am at a loss as to how to do the calculation and store the result in an int variable. Can someone out in cyberworld help? Thanks to anyone who responds.
CODE
import java.util.*;
public class TestNumbers
{
public static void main(String args[])
{
Scanner input = new Scanner(System. in);
int result;
System.out.prin tln("Enter a number:");
double num1 = input.nextDoubl e();
System.out.prin tln();
System.out.prin tln("Enter second number:");
float num2 = input.nextFloat ();
System.out.prin tln();
System.out.prin tln("Enter third number:");
long num3 = input.nextLong( );
System.out.prin tln();
System.out.prin tln("Enter fourth number:");
int num4 = input.nextInt() ;
System.out.prin tln();
System.out.prin tln("Enter fifth number:");
byte num5 = input.nextByte( );
System.out.prin tln();
}
}
Comment