Ajax
ASP
C,C++
C#,.NET
CSS,HTML
Delphi,Kylix
Experience
Flash
Java
JavaScript
PHP
Python
QT
SQL
ShellScript
VB
U :
P :
Register
Lost Password
Other Links
Code Archive
Save Giovanni
Java Category Code
Real Name
:
Ahmet Tuna
Subject
:
text dosyadan sayı okuma
Description
:
text dosyadan okunan syıları insertion sort ile sıralayarak sıralama sürasini yazan program
import com.boragungoren.java.Klavye; import java.io.*; import java.util.*; class proje3{ int[] d; public static void siralama(int d[]){ int i,k,j,w,a,ekle; a=0; w=0; for(i=1;i<d.length;i++){ ekle=d[i]; w=0; a=0; for(k=i-1;k>=0;k--){ w=w+1; if(ekle<=d[k]){ d[k+1]=d[k]; d[k]=ekle; a=a+1; }} System.out.println ("SIRALAMADAN SONRA :"); for(j=0;j<d.length;j++){ System.out.print (" "+d[j]+" "); } System.out.println ("//"+i+" İNCİ DONGUDE "+w+" KARSILASTIRMA "+a+" YER DEGİSTİRME "); } } public static void dosyadanoku(int[] d) { try { FileReader fr = new FileReader("input.txt"); //text dosyanin adı BufferedReader br = new BufferedReader(fr); String ss; int i=0; while ((ss = br.readLine()) != null) { // Text dosyadan bir satir okunuyor StringTokenizer st = new StringTokenizer(ss, "-"); // ayrac ; karakteri while (st.hasMoreTokens()) { String str = st.nextToken(); // string içindeki ";" ler arasındaki kısımlar alınıyor. d[i++]=Integer.parseInt(str); System.out.print (d[i]+"-"); // BURADAKİ STR Yİ UYGUN SEKİLDE KULLANACAKSINIZ } System.out.println("SATIR SONA ERDI"); } } catch (IOException ex) { System.out.println("DOSYA OKUMA HATASI"); } catch (Exception ex) { System.out.println("KODLAMA HATASI"+ex); } } public static void main(String args[]){ System.out.println ("DİZİNİN DOSYADAN OKUNMASI İCİN 0 I,"); System.out.println ("VERİLERİ ELLE GİRMEK İCİN 1 I,"); System.out.println ("DİZİYİ RASGELE DOLDURMAK İCİN 2 YI TUSLAYINIZ"); int secım=Klavye.intOku(); if(secım==0){ int[] d=new int [10]; dosyadanoku(d); long sure1 = System.currentTimeMillis(); siralama(d); long sure2= System.currentTimeMillis()-sure1; System.out.println (); System.out.println ("*******************"); System.out.println ("SURE :"+sure2+"************"); System.out.println ("*******************"); } if(secım==1){ System.out.println ("BOYUT GIRIN"); int n=Klavye.intOku(); int[] d=new int [n]; for(int y=0;y<d.length;y++){ System.out.println ("SAYI GİR"); d[y]=Klavye.intOku(); } long sure1 = System.currentTimeMillis(); siralama(d); long sure2= System.currentTimeMillis()-sure1; System.out.println (); System.out.println ("*******************"); System.out.println ("sure:"+sure2+"**********"); System.out.println ("*******************"); } if(secım==2){ Random r=new Random();int i,toplam; System.out.println ("BOYUT GİRİN"); int z=Klavye.intOku(); int d[]=new int[z]; for (i=0;i<d.length;i++){ d[i]=r.nextInt()%100; System.out.println (i+":"+d[i]);} long sure1 = System.currentTimeMillis(); siralama(d); long sure2= System.currentTimeMillis()-sure1; System.out.println (); System.out.println ("*******************"); System.out.println ("sure:"+sure2+"************"); System.out.println ("*******************"); } } }
Rating
:
3.50
(out of 5)
Visitor Voting Booth
:
Excellent
Very Good
Good
Fair
Poor
Copyright © 2006 SharingCode.NET . All rights reserved. Hosted By: SisNetworks