-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasitMethodOrnekleri2.java
65 lines (59 loc) · 2.09 KB
/
BasitMethodOrnekleri2.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Scanner;
public class BasitMethodOrnekleri2 {
public static void main(String[] args) {
System.out.println(toplama());
}
public static int toplama() {
int toplam = 0;
Scanner input = new Scanner(System.in);
System.out.println("Toplanılacak sayıları giriniz. Sonlandırmak için 0 rakamını kullanınız.");
for (; ; ) {
int giris = input.nextInt();
toplam = giris + toplam;
if (giris == 0) {
break;
}
}
System.out.println("Toplam: ");
return toplam;
}
public static int carpma() {
int carpim = 1;
Scanner input = new Scanner(System.in);
System.out.println("çarpılacak sayıları giriniz. Sonlandırmak için 0 rakamını kullanınız.");
for (; ; ) {
int giris = input.nextInt();
if (giris == 0) {
break;
}
carpim = giris * carpim;
}
System.out.println("Carpım: ");
return carpim;
}
public static float bölme() {
Scanner input = new Scanner(System.in);
System.out.println("bölünecek sayıları giriniz.");
int sayi1 = input.nextInt();
int sayi2 = input.nextInt();
int a = Math.max(sayi1, sayi2);
int b = Math.min(sayi1, sayi2);
float sonuc = a / b;
System.out.println("Bölme: ");
return sonuc;
}
public static int cikarma() {
int sonuc=0;
Scanner input = new Scanner(System.in);
System.out.println("Çıkarılacak sayıları giriniz. Sonlandırmak için 0 rakamını kullanınız.");
for (; ; ) //For ile sonsuz döngü bu şekilde yapılabilir, burada daha doğru kullanım while ya da do wihle döngülerinden biri olacaktır.
{
int giris = input.nextInt();
if (giris == 0) {
break;
}
sonuc = Math.max(sonuc, giris) - Math.min(sonuc, giris);
}
return sonuc;
}
}