III.
Write the source code of java for these:
a. WAP to print the cube of a number entered by the user.
b. WAP to print the sum, difference, product of the two numbers entered by the user.
c.WAP to print quotient and remainder of the numbers accepted by the user
are the following:
Answers
Program:
import java.util.*;
public class Progs{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("a.)Enter a number to print it's cube:");
int c = sc.nextInt();
System.out.println("cube of "+c+" is : "+(c*c*c));
System.out.print("b.)Enter 2 numbers to print their sum,diff,pro :");
int a = sc.nextInt(),b=sc.nextInt();
System.out.println("Sum of "+a+" and "+b+" is : "+(a+b));
System.out.println("Difference of "+a+" and "+b+" is : "+(a-b));
System.out.println("Product of "+a+" and "+b+" is : "+(a*b));
System.out.println("c)Enter 2 nums to print quotient and reminder : ");
int n1 = sc.nextInt(),n2 = sc.nextInt();
System.out.println("Quotient of "+a+" and "+b+""+(a/b));
System.out.println("Reminder of "+a+" and "+b+""+(a%b));
}
}
Output:
a.)Enter a number to print it's cube: 10
cube of 10 is : 1000
b.)Enter 2 numbers to print their sum,diff,pro : 5
3
Sum of 5 and 3 is 8
Difference of 5 and 3 is 2
product of 5 and 3 is 15
c)Enter 2 nums to print quotient and reminder : 10
5
Quotient of 10 and 5 is 2
Reminder of 10 and 5 is 0
Explanation:
- instead of writing three different programs for them, i ended up writing all the 3 programs code into one program
- it will save time and you can take the logic from those 3 and use same syntax and delete the rest of 2 then you will get the output of your chosen code
- and instead of initializing a variable to store the result, waste of memory so i printed directly in the print statement
---Hope you got what you wanted, if you liked it mark as brainliest,it would really help me. :)