//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 : :
//please save this code as Cap.java or download the given file and compile it with " javac Cap.java " //After successful compilation run this with " java Cap" at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Cap { public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); System.out.println("Enter a line:"); s=in.nextLine(); char c; int ct=0; for(int i=0;i<s.length();i++) { c=s.charAt(i); if(c>=65 && c<=90) { ct++; } } System.out.println("total number of words start with capital letters are :"+ct); } } OUTPUT : :
//please save this code as Palindrome.java or download the given file and compile it with " javac Palindrome.java " //After successful compilation run this with " java Palindrome" at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Palindrome { public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); boolean f=false; System.out.println("Enter String to check it's palindrome or not::"); s=in.next(); int l=s.length()-1; for(int i=0;i<l;i++,l--) { if(s.charAt(i)==s.charAt(l)) { f=true; } else { f=false; } } if(f) { System.out.println("String is palindrome"); } else { System.out.println("String is not palindrome"); } } } OUTPUT : :
//please save this code as Count.java or download the given file and compile it with " javac Count.java " //After successful compilation run this with " java Count" at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Count { public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); System.out.println("Enter a line:"); s=in.nextLine(); char c; int sp=0,cl=0,cv=0,cs=0,ci=0; for ( int i=0;i<s.length();i++) { c=s.charAt(i); if(c>=65 && c<=90 || c>=97 && c<=122) // condition of A to Z and a to z { cl++; // alphabet's counter incremented if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U'|| c=='a' || c=='e' || c=='i' || c=='o' || c=='u') { cv++; // vowel's counter incremented } } else if(c>=48 && c<=57) { ci++; // digit's counter incremented } else if(c==' ') { sp++; } else { cs++; // special char's counter incremented } } System.out.println("total number of alphabet in this string is "+cl); System.out.println("total number of vowel in this string is "+cv); System.out.println("total number of consonant in this string is "+(cl-cv)); System.out.println("total number of digit in this string is "+ci); System.out.println("total number of space in this string is "+sp); System.out.println("total number of special char in this string is "+cs); } } OUTPUT : :
//please save this code as SubString.java or download the given file and compile it with " javac SubString.java " //After successful compilation run this with " java SubString " at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class SubString { public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); System.out.println("Enter a String :"); s=in.next(); int l=s.length(); System.out.println("Length of the string "+s+" is "+l); System.out.println("Your sub String is:"+s.substring(l/2)); } } OUTPUT : :
This program takes two arguments statically and operates arithmetic operation on this two. //please save this code as Prog2.java or download the given file and compile it with " javac Prog2.java " //After successful compilation run this with " java Prog2 " at CMD // Make sure you have java already //installed in your system CODE : : class Prog2 { public static void main(String m[]) { String s1=m[0]; int a=6,b=2; System.out.println("The two values are"); System.out.println("a="+a); System.out.println("b="+b); int c=a*b; System.out.println("The Multiplication is:"+c); c=a/b; System.out.println("The Division is:"+c); c=a+b; System.out.println("The addition is:"+c); c=a-b; System.out.println("The subtraction is:"+c); } } OUTPUT : : The two values are a=6 b=2 The Multiplication is : 12 The Division is : 3 The addition is : 8 The subtraction is : 6
|
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 |