Posts

Showing posts from November, 2016

5th sem OOPJ Create a class called Student. Write a student manager program to manipulate the student information from files by using DataInputStream and DataOutputStream.

import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; /**  *  * @author Yash  */ public class pra13 {     public static void main(String arg[]) throws FileNotFoundException, IOException{         DataInputStream din = new DataInputStream(new FileInputStream("new.txt"));         DataOutputStream dout = new DataOutputStream(new FileOutputStream("output1.txt"));                 String str;                 while((str=din.readLine()) != null){         String s2 = str.toUpperCase();         dout.writeBytes(s2 + "\n");         }         din.close();         dout.close();     } }

5th sem OOPJ Create a class called Student. Write a student manager program to manipulate the student information from files by using BufferedReader and BufferedWriter.

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /**  *  * @author Yash  */ public class pra12 {     public static void main(String arg[]) throws FileNotFoundException, IOException{         BufferedReader br = new BufferedReader(new FileReader("new.txt"));         BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));                 int i;         do{             i=br.read();             if(i != -1){                 if(Character.isUpperCase((char)i)){                 bw.write(Character.toLowerCase((char)i));                 }else{                     bw.write((char)i);                 }             }         }while(i != -1);         br.close();         bw.close();                 } }

5th sem OOPJ Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

import java.io.FileInputStream; import java.io.FileOutputStream; /**  *  * @author Yash  */ public class pra11 {     public static void main(String arg[])throws Exception{         FileOutputStream fout = new FileOutputStream("new.txt"); //new.txt shold be on same directory of the java program file.         String s1 = "\n Student's name : Mr. abc\n Branch : Computer Engineering\n Sem : 5th\n Batch : H";         byte b[] = s1.getBytes();         fout.write(b);                 FileInputStream fin = new FileInputStream("new.txt");         int i = 0;         while((i=fin.read()) != -1){             System.out.print((char)i);         }         fin.close();     } }

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

import java.util.Scanner; /**  *  * @author Yash  */ public class pra10 {     public static void main(String arg[]){         int i,j,k,n;         Scanner sc = new Scanner(System.in);         System.out.print("Enter the Range :");         n=sc.nextInt();         for(i=1;i<=n;i++){             for(j=n;j>=i;j--){                 System.out.print(" ");             }             for(k=1;k<=i;k++){                 System.out.print(" *");             }             System.out.println(" ");         }         for(i=1;i<=n;i++){             for(j=0;j<=i;j++){                 System.out.print(" ");             }             for(k=n;k>i;k--){                 System.out.print(" *");             }             System.out.println(" ");         }     } }

5th sem OOPJ Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows.

import java.util.Scanner; /**  *  * @author Yash  */ public class pra9 {     public static void main(String arg[]){         char c;         int i,j,k;         Scanner sc = new Scanner(System.in);         String s1;         System.out.print("Enter the String :");         s1=sc.next();         for(i=0;i<s1.length();i++){             for(j=0;j<=s1.length()-i;j++){                 System.out.print(" ");             }             for(k=0;k<=i;k++){                 c = s1.charAt(k);                 System.out.print(c+" ");             }             System.out.println(" ");         }     } }

5th sem OOPJ Create a class which asks the user to enter a sentence, and it should display count of each vowel type in the sentence. The program should continue till user enters a word “quit”. Display the total count of each vowel for all sentences.

import java.util.*; /**  *  * @author Yash  */ public class pra8 { public static void main(String arg[]){         String s1 = new String();                 while(!s1.equals("quit")){         char ch;         int vol=0,cont=0;         System.out.println("Enter the String..");         Scanner sc = new Scanner(System.in);         s1 = sc.nextLine();         StringBuffer sb = new StringBuffer(s1);         for(int i=0;i<sb.length();i++){             ch = sb.charAt(i);             if( ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U'){                 vol++;             }else{                 cont++;             }         }         System.out.println("voweles : "+vol);         System.out.println("Consonants :" +cont);         }     }   }

5th sem OOPJ Write a program to find that given number or string is palindrome or not.

import java.io.*; import java.util.*; /**  *  * @author Yash  */ class pra7{     public static void main(String arg[]){                 Scanner sc = new Scanner(System.in);                 System.out.println("Enter String :");         int n = sc.nextInt();                 int r,sum=0,temp;                   temp=n;           while(n>0){           r=n%10;  //getting remainder         sum=(sum*10)+r;           n=n/10;               }           if(temp==sum)               System.out.println("palindrome number ");           else               System.out.println("not palindrome");     }   }

5th sem OOPJ Write a program to count the number of words that start with capital letters.

import java.io.*; /**  *  * @author Yash  */ class pra6{     public static void main(String arg[]) throws IOException{         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));                 int num=0;         System.out.println("Write a line :");         String str  = br.readLine();                 for(int i=0;i<str.length();i++){             if(Character.isUpperCase(str.charAt(i))){              num++;             }         }         System.out.println("The Number of Upper case is : "+num);     }   }

5th sem OOPJ Write a program to accept a line and check how many consonants and vowels are there in line.

import java.io.*; /**  *  * @author Yash  */ class pra5{     public static void main(String arg[]) throws IOException{         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         char ch;         int vol=0,cont=0;         System.out.println("Write a line :");         String str  = br.readLine();                 for(int i=0;i<str.length();i++){             ch = str.charAt(i);             if( ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U'){                 vol++;             }else{                 cont++;             }         }         System.out.println("voweles : "+vol);         System.out.println("Consonants :" +cont);     }   }

5th sem OOPJ Write a program to find length of string and print second half of the string.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra4{     public static void main(String arg[]){         Scanner sc = new Scanner(System.in);         DecimalFormat numfor = new DecimalFormat("#.000");//This is to fix after the decimal size.                 System.out.println("Enter your String :");         String str = sc.nextLine();         System.out.println("The Length of string is : "+str.length());         System.out.println("Second half of string is :"+str.substring(str.length()/2,str.length()));             }   }

5th sem OOPJ Write a program to enter two numbers and perform mathematical operations on them.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra3{     public static void main(String arg[]){         Scanner sc = new Scanner(System.in);         Scanner sc1 = new Scanner(System.in);                 double a,b;                                 System.out.println("Select  '+' '-' '*' '/' ");         System.out.print("Enter the value of a : ");         a = sc.nextDouble();         System.out.print("Enter the value of b : ");         b = sc.nextDouble();         System.out.println("Select you choice:");         String cho = sc1.nextLine();         switch(cho){             case "+" :                 System.out.println("You have selected addition ");                 System.out.println("Your Answer is : "+(a+b));                 break;             case "-":                 System.out.println("You have selected subtrac

5th sem OOPJ Write a program that calculates percentage marks of the student if marks of 6 subjects are given.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra2{     public static void main(String a[]){         Scanner sc = new Scanner(System.in);         DecimalFormat numfor = new DecimalFormat("#.000");//This is to fix after the decimal size.         int arr[] = new int[6];         int total=0;                 for(int i=0;i<arr.length;i++){             System.out.println("Enter sunject "+(i+1)+" Marks:");             arr[i] = sc.nextInt();             total +=arr[i];         }         double per = total/6;         System.out.println("Percentage of 6 subject is"+numfor.format(per));     }   }

5th sem OOPJ Write a program to convert rupees to dollar. 60 rupees=1 dollar.

import java.text.*; import java.util.*; /**  *  * @author Yash  */ class pra1{     public static void main(String a[]){         Scanner sc = new Scanner(System.in);         DecimalFormat numfor = new DecimalFormat("#.000");//This is to fix after the decimal size.         System.out.println("Enter the rupees :");         double rup = sc.nextInt();         double dol = rup/60;         System.out.println("Your Current doller is : " + numfor.format(dol));     }   }