Docsity

Java Programming Examples: If Else Statement, User Input, Account Class, Car Class, Exercises of Programming Languages

Toggle sidebar
bg1
If Else Basit Örneği
int x = 67;
int y = 89;
int toplam = x + y ;
if ( toplam < 100){
System.out.println("Sonucunuz Yanlış");
}
else if (toplam > 100)
System.out.println("Sonucunuz Doğru");
KULLANICIDAN VERİ ALINARAK YAZILAN BİR IF ELSE ÖRNEĞİ
import java.util.Scanner ;
public class Butterfly {
public static void main (String []args ){
Scanner s = new Scanner (System.in);
System.out.println("İlk Sayıyı Giriniz : ");
int sayı1=s.nextInt();
System.out.println("İkinci Sayıyı Giriniz : ");
int sayı2=s.nextInt();
if (sayı1>sayı2)
System.out.println(sayı1+" , "+sayı2+" ' den büyüktür");
else
System.out.println(sayı1+" , "+sayı2+" 'den küçüktür");
Banking Account
Accounts Sınıfı;
public class Accounts {
private double accountA ;
private double accountB;
public double getAccountA() {
return accountA;
}
public void setAccountA(double accountA) {
this.accountA = accountA;
}
public double getAccountB() {
return accountB;
}
public void setAccountB(double accountB) {
this.accountB = accountB;
}
}
Main Class;
pf3

Partial preview of the text

Download Java Programming Examples: If Else Statement, User Input, Account Class, Car Class and more Exercises Programming Languages in PDF only on Docsity!

If Else Basit Örneği

int x = 67;

int y = 89;

int toplam = x + y ;

if ( toplam < 100){

System.out.println("Sonucunuz Yanlış");

else if (toplam > 100)

System.out.println("Sonucunuz Doğru");

KULLANICIDAN VERİ ALINARAK YAZILAN BİR IF ELSE ÖRNEĞİ

import java.util.Scanner ;

public class Butterfly {

public static void main ( String []args ){

Scanner s = new Scanner ( System. in );

System. out .println("İlk Sayıyı Giriniz : ");

int sayı1 =s.nextInt();

System. out .println("İkinci Sayıyı Giriniz : ");

int sayı2 =s.nextInt();

if (sayı1>sayı2)

System. out .println(sayı1+" , "+sayı2+" ' den büyüktür");

else

System. out .println(sayı1+" , "+sayı2+" 'den küçüktür");

Banking Account

Accounts Sınıfı;

public class Accounts { private double accountA ; private double accountB; public double getAccountA() { return accountA; } public void setAccountA( double accountA) { this .accountA = accountA; } public double getAccountB() { return accountB; } public void setAccountB( double accountB) { this .accountB = accountB; } }

Main Class;

public class MainClass { public static void main (String args[]){ Transaction Balance = new Transaction (); Transaction Deposit = new Transaction (); Accounts accountA = new Accounts (); Accounts accountB = new Accounts (); accountA.equals(Balance); accountB.equals(Deposit); System. out .println( "accountA = " + Balance.getBalance()); System. out .println("accountB = " + Deposit.getDeposit()); } }

Transaction sınıfı;

public class Transaction { private double Balance = 500; private double Deposit = 400; private double Amount = 300; Accounts accountA = new Accounts (); Accounts accountB = new Accounts (); public double getDeposit() { return Deposit + Amount ; } public void setDeposit( double deposit) { Deposit = deposit; } public double getAmount() { return Amount; } public void setAmount( double amount) { Amount = amount; } public double getBalance() { return Balance - Amount; } public void setBalance() { this .Balance = Balance ; } }

ARABA KODU ;

Car Classı

public class car { String Color; String Model; double Engine; int Doors;