JAVA – SAYI TEK Mİ? ÇİFT Mİ?
Kullanıcıdan sayıyı aldıktan sonra sayının modunu alıp kalan değere bakarak if else ile tek veya çift olduğunu ekrana yazdırıyoruz.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| package hafta2;import java.util.*;public class Hafta2 { public static void main(String[] args) { Scanner giris=new Scanner(System.in); int birsayi; System.out.print("Bir sayı girin"); birsayi=giris.nextInt(); if (birsayi %2==0) { System.out.print("Sayı Çift Sayıdır"); } else { System.out.print("Sayı Tek Sayıdır"); } } } |
Hiç yorum yok:
Yorum Gönder