Вы находитесь на странице: 1из 12

class aa { public static void main(String arg[]) { System.out.print("welcome"); int x[]={4,66,77,8,34,2,9,89,50,99}; for(int a=0;a<10;a++) { System.out.

print("\n Number = "+x[a]); }

} } ///////////////////// import java.io.*; import java.util.*; class token1 { public static void main(String args[])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("Enter a String"); StringTokenizer s1=new StringTokenizer(br.readLine(),","); int cou=0; cou=s1.countTokens(); System.out.println("No of tokens ="+cou); for(int c=0;c<cou;c++) { System.out.println(s1.nextToken()); }

} }

///////////////////////////class delhi

{ public static void main(String ar[]) { String str1="India celebrates January 26 as Republic day"; String str2="Independence"; String str3="15" String str4="August";

int x,y,z; char c; for(x=0;x<len;x++) { c=str1.charAt(x); if(c==32) { z++; } } String arr1[]=new String[z+1]; int len=str1.length(); for(x=0;x<len;x++) { c=str1.charAt(x); if(c!=32) {

} }

} ////////// import java.io.*; class combi2 { public static void main(String args[])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("Enter the name of file you want to copy with extension"); String fn = br.readLine();

FileWriter fw=new FileWriter(fn,true); BufferedWriter bw=new BufferedWriter(fw); PrintWriter of =new PrintWriter(bw); ////////////////// System.out.println("Enter the name of file you want to create with extension"); String f2 = br.readLine(); FileWriter fw1=new FileWriter(f2,true); BufferedWriter bw1=new BufferedWriter(fw1); PrintWriter of1 =new PrintWriter(bw1);

///////////////////// try { FileReader file=new FileReader(fn); BufferedReader fileInput=new BufferedReader(file); String text; int i=0;

while( (text=fileInput.readLine()) != null) { i++; System.out.println(i+" "+text); of1.println(text); } fileInput.close(); } /////////////////////////////////// catch(IOException e) { System.err.println(e); } of.close(); of1.close();

} } } ////////////////////// import java.io.*; class combi1 { public static void main(String args[])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("Enter the name of file you want to create long with extens ion"); String fn=br.readLine(); try { FileWriter fw=new FileWriter(fn,true); BufferedWriter bw=new BufferedWriter(fw); PrintWriter of =new PrintWriter(bw); for(int x=0;x<5;x++) { System.out.println("Enter name : "); String name=br.readLine(); of.println(name); }

of.close(); } catch(IOException e) { System.err.println(e); } try { FileReader file=new FileReader(fn); BufferedReader fileInput=new BufferedReader(file); String text; int i=0; while( (text=fileInput.readLine()) != null) { i++; System.out.println(i+" "+text); } fileInput.close(); } catch(IOException e) { System.err.println(e); } } }

////////////////// import java.io.*; class files3 { public static void main(String args[]) { String fn="stud1.txt"; InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); try { int rno; float marks; FileOutputStream fw =new FileOutputStream(fn,true); DataOutputStream dw=new DataOutputStream(fw);

for(int x=0;x<5;x++) { System.out.print("Enter Rollno :"); rno=Integer.parseInt(br.readLine()); System.out.print("Enter Marks :"); marks=Float.parseFloat(br.readLine()); dw.writeInt(rno); dw.writeFloat(marks); } dw.close(); fw.close(); } catch(IOException e) { System.err.println(e); } } } ///////////////////////// import java.io.*; class find2 { public static void main(String args[])throws IOException { FileReader file=new FileReader("names.txt"); BufferedReader fileInput=new BufferedReader(file); String nam="anil"; int f=0; String text; int i=0; while( (text=fileInput.readLine()) != null) { i++; if(nam.compareTo(text)==0) f=1;

} if(f==1) System.out.print("Found"); else

System.out.print("Not Found");

fileInput.close(); } } ////////////////////// import java.io.*; import java.util.*; class token1 { public static void main(String args[])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("Enter a String"); StringTokenizer s1=new StringTokenizer(br.readLine()); int cou=0; cou=s1.countTokens(); System.out.println("No of tokens ="+cou); for(int c=0;c<cou;c++) System.out.println(s1.nextToken()); } }

///////////// class stack { int s[]=new int[20]; int sp,n; //////////////////////////////////// stack(int nm) { for(int x=0;x<20;x++) s[x]=0;

sp=-1; n=nm; } ///////////////////////////////////////// void pushdata(int item) { if(sp==(n-1)) System.out.println("Stack Over flows"); else { sp++; s[sp]=item; } } ////////////////////////////////////////// void popdata() { int v; if(sp==-1) { System.out.println("Stack Underflow"); } else { v=s[sp]; System.out.println("Popped out elements is == "+v); s[sp]=0; sp--; } } //////////////////////////////////////////

void disp() { for(int x=0;x<10;x++) System.out.println(s[x]); } //////////////////////////////////////////////////////////////// void disp2() { if(sp==-1) System.out.println("Stack is Empty"); else { System.out.println("SP--->|"+s[sp]+"|"); System.out.print("___");

for(int i=sp-1;i>=0;i--) { System.out.println(" | "+s[i]+" | "); System.out.println("____"); } } } } class stack1 { public static void main(String args[]) { stack s1=new stack(10); for(int y=0;y<12;y++) { s1.pushdata(2*y); } s1.disp2(); System.out.println("\t\t =-=-=-=-= BEFORE POP DATA =-=-=-=-=-"); /////////////////////////////// for(int y=0;y<10;y++) { s1.popdata(); } /////////////////////////////// System.out.println("\t\t/=/=/=/=/=/=/=/=/=/=/=/=/=/==-=-=-=-=-"); s1.disp2(); System.out.println("\t\t =-=-=-=-= AFTER POP DATA =-=-=-=-=-"); //////////////////////////////////////// s1.disp(); } } /////////////// class str10 { public static void main(String args[]) { String s1="Razi Ahmad Siddiqui kareli"; String s2; int x,y,z,l=0,sp=0,ze=0,ze1=0; char c; l=s1.length();

System.out.print(s1.charAt(0)+"."); for(x=0;x<l;x++) { c=s1.charAt(x); if(c==32) ze++; } for(x=0;x<l;x++) { c=s1.charAt(x); if(c==32) { ze1++; if(ze==ze1) continue; System.out.print(s1.charAt(x+1)+"."); } if(ze==ze1) System.out.print(s1.charAt(x)); } } } ////////////// class str11 { public static void main(String args[]) { String s1="Hello dear friend how are you "; String s2="",s3,tmp=""; char c,d; int x,y,z,a=0,bb=0; int l=s1.length();

for(x=0;x<l;x++) { c=s1.charAt(x); if(c==32) { bb++; }

} String arr[]=new String[bb];

for(x=0;x<l;x++) { c=s1.charAt(x); if(c!=32) { s2=s2+c; } else { arr[a]=s2; a++; s2=""; } } // System.out.print(a);

for(z=0;z<bb;z++) { for(y=0;y<bb-1;y++) { if(arr[y].length() > arr[y+1].length() ) { tmp=arr[y]; arr[y]=arr[y+1]; arr[y+1]=tmp; } } } for(y=0;y<bb;y++) { System.out.print(arr[y]+ " "); } } } import java.io.*; import java.util.*; class token1 { public static void main(String args[])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr);

System.out.println("Enter a String"); StringTokenizer s1=new StringTokenizer(br.readLine(),","); int cou=0; cou=s1.countTokens(); System.out.println("No of tokens ="+cou); for(int c=0;c<cou;c++) { System.out.println(s1.nextToken()); }

} }

Вам также может понравиться