In: Computer Science
• Using the Scanner class to obtain input from the user. • Using printf to output information to the user. • Using arithmetic operators to perform calculations. • Using if statements to make decisions based on the truth or falsity of a condition. • Using relational operators to compare variable values. Project 1: 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). Sample Output: CSC 110 Lab 4 Page 1 of 3 Project 2. Write an application that asks the user to enter two integers, obtains them from the user and displays the larger number followed by the words “is larger”. If the numbers are equal, print the message “These numbers are equal”
import java.util.Scanner;
public class Larger {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.println("Enter 2
numbers: ");
// reading 2 numbers
int n1 = sc.nextInt();
int n2 = sc.nextInt();
// printing sum and difference and
product and division
System.out.println("Sum : " + (n1 +
n2));
System.out.println("Difference: " +
(n1 - n2));
System.out.println("Product : " +
(n1 * n2));
System.out.println("Div : " + (n1 /
n2));
// checking which one is larger and
printing its details
if (n1 > n2) {
System.out.println(n1 + " is larger");
} else if (n2 > n1) {
System.out.println(n2 + " is larger");
} else {
System.out.println("Both are equal");
}
}
}
Note : If you like my answer please rate and help me it is very Imp for me