Created
September 5, 2020 11:45
-
-
Save mrnirva/cfb06a0dbaf6650f834ce83f7ad8968b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scannerdersi; | |
import java.util.Scanner; | |
public class ScannerDersi { | |
public static void main(String[] args) { | |
// Scanner nesnesini oluşturmak | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Yapmak İstediğiniz İşlemi Seçin" | |
+ "\n[1] Toplama" | |
+ "\n[2] Çıkarma" | |
+ "\n[3] Çarpma" | |
+ "\n[4] Bölme"); | |
int girdi = sc.nextInt(); | |
System.out.println("Sayıları Giriniz (Virgül İle Ondalık Girebilirsiniz)"); | |
System.out.println("Birinci Sayı: "); | |
float sayi1 = sc.nextFloat(); | |
System.out.println("İkinci Sayı: "); | |
float sayi2 = sc.nextFloat(); | |
float sonuc = islemYap(girdi,sayi1,sayi2); | |
System.out.println("Sonuç: "+sonuc); | |
} | |
// İşlemleri yapan metodumuz | |
static float islemYap(int girdi, float sayi1, float sayi2){ | |
switch (girdi) { | |
case 1: | |
return sayi1 + sayi2; | |
case 2: | |
return sayi1 - sayi2; | |
case 3: | |
return sayi1 * sayi2; | |
case 4: | |
// Kontrol mekanizması | |
if(sayi2 == 0){ | |
System.out.println("Payda Sıfır Olamaz"); | |
return 0; | |
}else{ | |
return sayi1 / sayi2; | |
} | |
default: | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment