Computer Science, asked by Ankush8038, 7 months ago

write a program In java plzz​

Attachments:

Answers

Answered by BRAINLIESTF
1

Answer:

Java is one of the most popular programming languages that is being widely used in the IT industry. It is simple, robust and helps us to reuse the code. In this article, let’s see some of the important programs to understand Java fundamentals.

Below is the list of programs that I will be covering in this article.

Basic Java Programs

Calculator Program in Java

Factorial Program using Recursion

Fibonacci Series Program

Palindrome Program in Java

Permutation and Combination Program

Pattern Programs in Java

String Reverse Program in Java

Mirror Inverse Program in Java

Advanced Java Programs

Binary Search Program in Java

HeapSort Program in Java

Removing Elements from ArrayList

HashMap Program in Java

Circular LinkedList Program in Java

Java DataBase Connectivity Program

Transpose of a Matrix Program

Let’s get started !

Basic Java Programs

1. Write a Java program to perform basic Calculator operations.

When you think about a calculator, operations like addition, subtraction, multiplication, and division comes into the mind. Let’s implement the basic calculator operations with the help of the below program.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

package Edureka;

import java.util.Scanner;

public class Calculator {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in);

System.out.print("Enter two numbers: ");

// nextDouble() reads the next double from the keyboard

double first = reader.nextDouble();

double second = reader.nextDouble();

System.out.print("Enter an operator (+, -, *, /): ");

char operator = reader.next().charAt(0);

double result;

//switch case for each of the operations

switch(operator)

{

case '+':

result = first + second;

break;

case '-':

result = first - second;

break;

case '*':

result = first * second;

break;

case '/':

result = first / second;

break;

// operator doesn't match any case constant (+, -, *, /)

default:

System.out.printf("Error! operator is not correct");

return;

}

//printing the result of the operations

System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, result);

}

}

Similar questions