Java - 15B

logistic_guy

Senior Member
Joined
Apr 17, 2024
Messages
2,213
Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference and quotient (division).
 
\(\displaystyle \textcolor{blue}{\text{package}}\) Moon;

\(\displaystyle \textcolor{blue}{\text{import}}\) java.util.Scanner;

\(\displaystyle \textcolor{blue}{\text{public}}\) \(\displaystyle \textcolor{blue}{\text{class}}\) \(\displaystyle \bold{Mario}\) {

\(\displaystyle \textcolor{blue}{\text{public}}\) \(\displaystyle \textcolor{blue}{\text{static}}\) \(\displaystyle \textcolor{blue}{\text{void}}\) \(\displaystyle \bold{main}\)(\(\displaystyle \textcolor{blue}{\text{String}}\)[] args){

Scanner input = \(\displaystyle \textcolor{blue}{\text{new}}\) Scanner(System.\(\displaystyle \textcolor{indigo}{\text{in}}\));

\(\displaystyle \textcolor{blue}{\text{int}}\) integer1;
\(\displaystyle \textcolor{blue}{\text{int}}\) integer2;

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).print(\(\displaystyle \textcolor{green}{\text{"Enter the first integer: "}}\));
integer1 = input.nextInt();

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).print(\(\displaystyle \textcolor{green}{\text{"Enter the second integer: "}}\));
integer2 = input.nextInt();

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).println(integer1 + \(\displaystyle \textcolor{green}{\text{" + "}}\) + integer2 + \(\displaystyle \textcolor{green}{\text{" = "}}\) + (integer1 + integer2));

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).println(integer1 + \(\displaystyle \textcolor{green}{\text{" x "}}\) + integer2 + \(\displaystyle \textcolor{green}{\text{" = "}}\) + (integer1 * integer2));

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).println(integer1 + \(\displaystyle \textcolor{green}{\text{" - "}}\) + integer2 + \(\displaystyle \textcolor{green}{\text{" = "}}\) + (integer1 - integer2));

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).printf(\(\displaystyle \textcolor{green}{\text{"\%d / \%d = \%.2f"}}\), integer1, integer2, (\(\displaystyle \textcolor{blue}{\text{double}}\))integer1 / integer2);

System.\(\displaystyle \textcolor{indigo}{\text{out}}\).println(\(\displaystyle \textcolor{green}{\text{"\textbackslash n"}}\) + integer1 + \(\displaystyle \textcolor{green}{\text{" \% "}}\) + integer2 + \(\displaystyle \textcolor{green}{\text{" = "}}\) + (integer1 % integer2));

}
}

\(\displaystyle \large\textcolor{indigo}{\bold{Sample.}}\)

sample_java.png
 
Top