Create an application that can add, minus, multiply and divide 2 integer numbers
ID: 3882963 • Letter: C
Question
Explanation / Answer
Hi,
here is the fully executable code,
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int a,b;
System.out.println("Enter first integer number");
a=sc.nextInt();
System.out.println("Enter second integer number");
b=sc.nextInt();
System.out.println("Add 2 integer numbers");
System.out.println(a+" + "+b+" ="+(a+b));
System.out.println("Enter first integer number");
a=sc.nextInt();
System.out.println("Enter second integer number");
b=sc.nextInt();
System.out.println("subtract 2 integer numbers");
System.out.println(a+"- "+b+" ="+(a-b));
System.out.println("Enter first integer number");
a=sc.nextInt();
System.out.println("Enter second integer number");
b=sc.nextInt();
System.out.println("multiply 2 integer numbers");
System.out.println(a+" * "+b+" ="+a*b);
System.out.println("Enter first integer number");
a=sc.nextInt();
System.out.println("Enter second integer number");
b=sc.nextInt();
System.out.println("divide 2 integer numbers");
System.out.println(a+" / "+b+" ="+a/b);
float c,d;
System.out.println("Enter first decimal number");
c=sc.nextFloat();
System.out.println("Enter second decimal number");
d=sc.nextFloat();
System.out.println("Add 2 decimal numbers");
System.out.println(c+" + "+d+" ="+(c+d));
System.out.println("Enter first decimal number");
c=sc.nextFloat();
System.out.println("Enter second decimal number");
d=sc.nextFloat();
System.out.println("subtract 2 decimal numbers");
System.out.println(c+"- "+d+" ="+(c-d));
System.out.println("Enter first decimal number");
c=sc.nextFloat();
System.out.println("Enter second decimal number");
d=sc.nextFloat();
System.out.println("multiply 2 decimal numbers");
System.out.println(c+" * "+d+" ="+c*d);
System.out.println("Enter first decimal number");
c=sc.nextFloat();
System.out.println("Enter second decimal number");
d=sc.nextFloat();
System.out.println("divide 2 decimal numbers");
System.out.println(c+" / "+d+" ="+c/d);
System.out.println("we have finished math operations");
}
}
Thumbs up if this was helpful, otherwise let me know in comments. Good Day.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.