William Crusader
Hectopat
- Katılım
- 11 Kasım 2020
- Mesajlar
- 5.359
- Makaleler
- 1
- Çözümler
- 15
Daha fazla
- Cinsiyet
- Erkek
- Meslek
- Yok
Söz veriyorum bir daha dil değiştirmiyeceğim. Java da çok zormuş ama
Kod:
[CODE lang="java" title="Java"]import java.util.Scanner; //imports scanner library (helps to get user input)
public class mainWork { //all cool code goes here
public static void main(String[] args) { //wise words a wise man once said
Scanner scanner = new Scanner(System.in); //scans (user input)
//The starting Menu
System.out.println("Welcome To Calculator Program. Which operation you would like to do?");
System.out.println("(Addittion = 1 , Extraction = 2 , Multiplication = 3 , Dividing = 4)");
int operation = scanner.nextInt();
//Gets the the operation user want to do
if (operation == 1) { //addition operation
System.out.println("What you wanna call X?");
int x = scanner.nextInt(); //gets x from user input
System.out.println("What you wanna call Y?");
int y = scanner.nextInt(); //gets y from user input
int result = x + y; //adds x and y together
System.out.println("The addition result: "+result); //shows result
}
if (operation == 2) {
System.out.println("What you wanna call X?");
int x = scanner.nextInt();
System.out.println("What you wanna call Y?");
int y = scanner.nextInt();
int result = x - y; //extracts y from x
System.out.println("The extraction result: "+result);
}
if (operation == 3) {
System.out.println("What you wanna call X?");
int x = scanner.nextInt();
System.out.println("What you wanna call Y?");
int y = scanner.nextInt();
int result = x * y; //multiples the x with y
System.out.println("The multiplication result: "+result);
}
if (operation == 4) { //divides x by y
System.out.println("What you wanna call X?");
int x = scanner.nextInt();
System.out.println("What you wanna call Y?");
int y = scanner.nextInt();
int result = x / y;
System.out.println("The dividement result: "+result);
}
else {
System.out.println("ERROR: You should write a number around 1-4, else it will give an error.");
}
}
} //brackets are important![/CODE]
Kod:
[CODE lang="java" title="Java"]import java.util.Scanner; //imports scanner library (helps to get user input)
public class mainWork { //all cool code goes here
public static void main(String[] args) { //wise words a wise man once said
Scanner scanner = new Scanner(System.in); //scans (user input)
//The starting Menu
System.out.println("Welcome To Calculator Program. Which operation you would like to do?");
System.out.println("(Addittion = 1 , Extraction = 2 , Multiplication = 3 , Dividing = 4)");
int operation = scanner.nextInt();
//Gets the the operation user want to do
if (operation == 1) { //addition operation
System.out.println("What you wanna call X?");
int x = scanner.nextInt(); //gets x from user input
System.out.println("What you wanna call Y?");
int y = scanner.nextInt(); //gets y from user input
int result = x + y; //adds x and y together
System.out.println("The addition result: "+result); //shows result
}
if (operation == 2) {
System.out.println("What you wanna call X?");
int x = scanner.nextInt();
System.out.println("What you wanna call Y?");
int y = scanner.nextInt();
int result = x - y; //extracts y from x
System.out.println("The extraction result: "+result);
}
if (operation == 3) {
System.out.println("What you wanna call X?");
int x = scanner.nextInt();
System.out.println("What you wanna call Y?");
int y = scanner.nextInt();
int result = x * y; //multiples the x with y
System.out.println("The multiplication result: "+result);
}
if (operation == 4) { //divides x by y
System.out.println("What you wanna call X?");
int x = scanner.nextInt();
System.out.println("What you wanna call Y?");
int y = scanner.nextInt();
int result = x / y;
System.out.println("The dividement result: "+result);
}
else {
System.out.println("ERROR: You should write a number around 1-4, else it will give an error.");
}
}
} //brackets are important![/CODE]