//please save this code as Pattern.java or download the given file and compile it with " javac Pattern.java " //After successful compilation run this with " java Pattern" at CMD // Make sure you have java already //installed in your system . use Notepad ++ NOTE : : Below code is Extended version of the above aim. CODE : : import java.lang.*; import java.util.*; class Pattern { public static void main(String m[]) { char c; int t,i,j; Scanner in= new Scanner(System.in); String s; int k,d; System.out.println("With Which Symbol you want to make Diamond??(Enter single char):"); s=in.next(); System.out.println("How many max "+s.charAt(0)+" :: "); t=in.nextInt(); t--; for(i=0;i<t;i++) { System.out.print("\t\t\t\t"); for(k=0;k<t-i;k++) { System.out.print(" "); } for(j=0;j<=i;j++) { System.out.print(s.charAt(0)+" "); } System.out.println(" "); } for(i=t;i>=0;i--) { System.out.print("\t\t\t\t"); for(k=t-i;k>0;k--) { System.out.print(" "); } for(j=i;j>=0;j--) { System.out.print(s.charAt(0)+" "); } System.out.println(" "); } } } OUTPUT : :
//please save this code as Countvowel.java or download the given file and compile it with " javac Countvowel.java " //After successful compilation run this with " java Countvowel" at CMD // Make sure you have java already //installed in your system . use Notepad ++ CODE : : import java.util.*; class Countvowel { public static int a,e,i,o,u; public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); while(true) { int ta=0,te=0,ti=0,to=0,tu=0; System.out.println("Enter A line :"); s=in.nextLine(); if(s.equals("quit")) { break; } else { int n=s.length()-1; for(int x=0;x<=n;x++) { switch(s.charAt(x)) { case 'a' : case 'A' : a++; ta++; break; case 'e' : case 'E' : e++; te++;break; case 'i' : case 'I' : i++; ti++; break; case 'o' : case 'O' : o++; to++; break; case 'u' : case 'U' : u++; tu++; break; } } System.out.println("\n\n In this statement:"); System.out.println("a comes: "+ta+" times"); System.out.println("e comes :"+te+" times"); System.out.println("i comes :"+ti+" times"); System.out.println("o comes: "+to+" times"); System.out.println("u comes :"+tu+" times"); } } System.out.println("\n\n Totle numbers of the vovels::"); System.out.println("a comes "+a+" times"); System.out.println("e comes "+e+" times"); System.out.println("i comes "+i+" times"); System.out.println("o comes "+o+" times"); System.out.println("u comes "+u+" times"); } } OUTPUT : :
Write an interactive program to print a string entered in a pyramid form.(Like one given below).12/8/2015 //please save this code as Pattern.java or download the given file and compile it with " javac Pattern.java " //After successful compilation run this with " java Pattern" at CMD // Make sure you have java already //installed in your system . CODE : : import java.util.*; class Pattern { public static void main(String m[]) { char c; int i,j; Scanner in= new Scanner(System.in); String s;//=new String("STREAM"); System.out.println("Enter A String::"); s=in.next(); int k,d; for(i=0;i<s.length();i++) { for(k=0;k<s.length()-i;k++) { System.out.print(" "); } for(j=0;j<=i;j++) { c=s.charAt(j); System.out.print(c+" "); } System.out.println(" "); } } } OUTPUT : :
|
Hello friends, i am a CSE student and i am going to upload all the programs of various language which might be in your collage practical list or might help you in performing your practicals in lab. Archives
August 2015
Categories |