Java da basit soru örnekleri 2
java örnekleri

0-1000 arası sayı oluşturup rakamları toplamını veren algoritma
Â
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication16;
Â
/**
 *
 * @author xoverx-
 */
public class JavaApplication16 {
Â
   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
Â
       int randomSayi = (int)(Math.random()*(1000)); //0 ile 1000 arasında sayı
       System.out.println("random sayi " + randomSayi); //üretilen sayıyı konsola bastırdıkÂ
       int birler = randomSayi %10; //birler basamağı
       randomSayi = randomSayi /10;
       int onlar = randomSayi %10;  //onlar basamağı      Â
       int yuzler = randomSayi /10; //yüzler basamağıÂ
       System.out.println("Toplamları ="+(birler+onlar+yuzler));Â
   }  Â
}
Â
Â
1
22
333
4444
şeklinde satır ve sütün oluşturmak için yazılan algoritma
Â
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication17;
import static java.lang.System.out;
import java.util.Scanner;
import static javafx.scene.input.KeyCode.O;
/**
 *
 * @author xoverx-
 */
public class JavaApplication17 {
   public static void main (String args[] ){
       System.out.println("Alt alta kaç sıra olsun ? ");
       Scanner inp = new Scanner(System.in);
       int sira = inp.nextInt();      Â
       for (int i=1; i<=sira; i ++)
       {
           for (int j=0; j
           {
               System.out.print(i);
           }
           System.out.println("");
       }  Â
   }
}
4 3 2 1 2 3 4
3 2 1 2 3 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
2 1 2
1
Sayiyi  eksilterek üçgen yapma
Â
import java.util.Scanner;Â
public class UcgenSayilar {
   public static void main(String args[])
   {
       System.out.println("Sayı giriniz? ");
       Scanner inp = new Scanner(System.in);
       int sira = inp.nextInt();
       for (int i = sira; i>=1; i--)
       {
           for (int j=i; j>=1; j--)
           {
               System.out.print(j+" ");
           }
           for (int k=2; k<=i; k++)
           {
               System.out.print(k+" ");
           }
           System.out.println("");
       }
   }
}
Â
Â
Â
Â
Â
Tanımlı iki sayının toplamı
Â
Â
public class JavaOrnekleri {Â Â
   public static void main(String[] args) {      Â
       int sayi1 = 10;
       int sayi2 = 20;Â
       int toplam = sayi1 + sayi2;Â
       System.out.println("Sayıların Toplamı: " + toplam);
   }  Â
}
Tepkileriniz Nedir?






