Nesne Tabanlı Programlama (Güz-2016) Hafta-9
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 |
package kok.ana; import kok.islemler.*; public class main { public main() { boolean durum=true; do{ String deger = System.console().readLine("1)Basamaktaki Rakamları Göster\n2)İkilik Sayı Sistemine Dönüştür\n3)Sayı Toplamı\n4)Çıkış\nSeçim Giriniz:"); switch(deger) { case "1": new basgoster(); break; case "2": new ikilik(); break; case "3": new sayitoplam(); break; case "4": durum=false; break; default: System.out.println("Geçerli Seçenek Girmediniz!"); } }while(durum); } public static void main(String[] args) { new main(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package kok.islemler; public class basgoster{ public basgoster() { String deger= System.console().readLine("Sayi Giriniz:"); try{ int sayi = Integer.parseInt(deger); System.out.print("Sayi Basamakları:"); while(sayi>0) { int bas = sayi%10; sayi=(sayi-bas)/10; System.out.print(bas+" "); } System.out.println(""); } catch(Exception ex) { } } |
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 |
package kok.islemler; public class ikilik{ public ikilik() { String deger= System.console().readLine("Sayi Giriniz:"); try{ int sayi = Integer.parseInt(deger); String sonuc=""; int x=sayi; while(sayi>0) { int k = sayi%2; sayi=sayi/2; sonuc=k+sonuc; } System.out.println(x+ " sayisinin ikilik karsiligi: "+sonuc); }catch(Exception ex) { } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
package kok.islemler; public class sayitoplam{ public sayitoplam() { String deger1 = System.console().readLine("1. Sayiyi Giriniz:"); String deger2 = System.console().readLine("2. Sayiyi Giriniz:"); try{ int a = Integer.parseInt(deger1); int b = Integer.parseInt(deger2); System.out.println("Sayilarin toplami: "+a+"+"+b+"="+(a+b)); }catch(Exception ex) { } } } |
NTP1 (Güz-2016) Hafta-9-jarfile NTP1 (Güz-2016) Hafta-9-kodlar
Okumaya devam et
Son Yorumlar