Jump to content

Help Me With This Simple Java Program

So I'm trying to create a calculator that only does division but displays the "real answer", " natural answer", and "natural remainder" all at the same time but you have to type in the same question twice to get it to display the natural answer and remainder. How do I make it so it displays all the results at the same time? I'm writing this into Eclipse and using it's built in compiler. If someone could let me know what I should do that would be excellent.

 

import java.util.Scanner;
 
class divisionremainder{
public static void main(String args[]){
Scanner keyboard = new Scanner(System.in);
 
System.out.println("-Division Calculator-");
 
double fnumD, snumD, divisionD;
    System.out.println("First Number: ");
    fnumD = keyboard.nextDouble();
    System.out.println("Second Number: ");
    snumD = keyboard.nextDouble();
    divisionD = fnumD / snumD;
    System.out.print("Real Answer = ");
    System.out.println(divisionD);
   
    int fnum, snum, division;
    fnum = keyboard.nextInt();
    snum = keyboard.nextInt();
    division = fnum / snum;
    System.out.print("Natural Answer = ");
    System.out.println(division);
   
    int fnumremainder, snumremainder, divisionremainder;
    fnumremainder = fnum;
    snumremainder = snum;
    divisionremainder = fnum % snum;
    System.out.print("Natural Remainder = ");
    System.out.print(divisionremainder);
 
}
}
Link to comment
Share on other sites

Link to post
Share on other sites

import java.util.Scanner; class divisionremainder{public static void main(String args[]){Scanner keyboard = new Scanner(System.in); System.out.println("-Division Calculator-"); double fnumD, snumD, divisionD;    System.out.println("First Number: ");    fnumD = keyboard.nextDouble();    System.out.println("Second Number: ");    snumD = keyboard.nextDouble();    divisionD = fnumD / snumD;    System.out.print("Real Answer = ");    System.out.println(divisionD);       int fnum, snum, division;    fnum = (int)fnumD;    snum = (int)snumD;    division = fnum / snum;    System.out.print("Natural Answer = ");    System.out.println(division);       int fnumremainder, snumremainder, divisionremainder;    fnumremainder = fnum;    snumremainder = snum;    divisionremainder = fnum % snum;    System.out.print("Natural Remainder = ");    System.out.print(divisionremainder); }}

what i changed:

 

  fnum = (int)fnumD;

  snum = (int)snumD;

 

 

test log:

run:-Division Calculator-First Number:13Second Number:5Real Answer = 2.6Natural Answer = 2Natural Remainder = 3BUILD SUCCESSFUL (total time: 3 seconds)

[spoiler=»--((¯`·._.·¤~●oO му яιg Oo●~¤·._.·´¯))--«] Case: Corsair 600T White       CPU: Core i7 3930k @ 4.3GHz                     SSD: Crucial M500 480GB

MB:    Asus P9X79 LE         GPU: Nvidia GTX 780 Reference             HDD: WD Caviar Green 3TB

PSU:   Seasonic X-1050      RAM: G.Skill Trident X 32GB @ 2.4GHz   ☃ There are 10 types of people in this world. Those who understand binary and those who don't.

Link to comment
Share on other sites

Link to post
Share on other sites

import java.util.Scanner; class divisionremainder{public static void main(String args[]){Scanner keyboard = new Scanner(System.in); System.out.println("-Division Calculator-"); double fnumD, snumD, divisionD;    System.out.println("First Number: ");    fnumD = keyboard.nextDouble();    System.out.println("Second Number: ");    snumD = keyboard.nextDouble();    divisionD = fnumD / snumD;    System.out.print("Real Answer = ");    System.out.println(divisionD);       int fnum, snum, division;    fnum = (int)fnumD;    snum = (int)snumD;    division = fnum / snum;    System.out.print("Natural Answer = ");    System.out.println(division);       int fnumremainder, snumremainder, divisionremainder;    fnumremainder = fnum;    snumremainder = snum;    divisionremainder = fnum % snum;    System.out.print("Natural Remainder = ");    System.out.print(divisionremainder); }}

what i changed:

 

  fnum = (int)fnumD;

  snum = (int)snumD;

 

 

test log:

run:-Division Calculator-First Number:13Second Number:5Real Answer = 2.6Natural Answer = 2Natural Remainder = 3BUILD SUCCESSFUL (total time: 3 seconds)

Thank you so much! I was pulling my hair out trying to fix this.

Link to comment
Share on other sites

Link to post
Share on other sites

Thank you so much! I was pulling my hair out trying to fix this.

np

[spoiler=»--((¯`·._.·¤~●oO му яιg Oo●~¤·._.·´¯))--«] Case: Corsair 600T White       CPU: Core i7 3930k @ 4.3GHz                     SSD: Crucial M500 480GB

MB:    Asus P9X79 LE         GPU: Nvidia GTX 780 Reference             HDD: WD Caviar Green 3TB

PSU:   Seasonic X-1050      RAM: G.Skill Trident X 32GB @ 2.4GHz   ☃ There are 10 types of people in this world. Those who understand binary and those who don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×