Java-İf-Else-Sorusu
Soru: Bir sayının pozitif, negatif veya sıfır olduğunu kontrol eden bir program yazın.
Çözüm:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Bir sayı giriniz: ");
int sayi = input.nextInt();
if ( sayi == 0 )
{
System.out.println("Girdiğiniz Sayı 0'a Eşittir.");
}
else if ( sayi > 0 )
{
System.out.println("Girdiğiniz sayı pozitiftir");
}
else if ( sayi < 0 )
{
System.out.println("Girdiğiniz sayı negatiftir");;
}
}
}
Post a Comment