Posts

Practical 13: Refine the student manager program to manipulate the student information from files by using the DataInputStream and DataOutputStream. Assume suitable data

Image
Program : import java.io.*; public class practical13 {     public static void main(String args[]) throws IOException {         DataInputStream dataIS = new DataInputStream(new FileInputStream("stdinfo.txt"));         DataOutputStream dataOS = new DataOutputStream(new FileOutputStream("newstdinfo.txt"));         // manipulate the student information from files         String str;         while ((str = dataIS.readLine()) != null) {             String upper = str.toUpperCase();             System.out.println(upper);             dataOS.writeBytes(upper + "  ,");...

Practical 12: Refine the student manager program to manipulate the student information from files by using the BufferedReader and BufferedWriter

Image
Program: import java.io.*; import java.util.*; class practical12 { public static void main(String pqr[]) throws Exception {         BufferedReader bufRead = new BufferedReader(new FileReader("stdinfo.txt"));         BufferedWriter bufWrite = new BufferedWriter(new FileWriter("newstdinfo.txt"));         int i;         // manipulate the student information from files         do {             i = bufRead.read();             if (i != -1) {                 if (Character.isUpperCase((char) i)) {            ...

Practical 11 : Create a class called Student. Write a student manager program to manipulate the student information from files by using FileInputStream and FileOutputStream

Image
Program : import java.io.FileInputStream; import java.io.FileOutputStream; public class practical11 {     public static void main(String[] args) {         System.out.println("-------Writing Data in File-------");         try {             FileOutputStream fout = new FileOutputStream("stdinfo.txt");             String str = "Nmae : Pruthviraj, Stream : INFORMATION TECHNOLOGY, Sem : 5th Sem";             byte b[] = str.getBytes();             fout.write(b);             fout.close();             System.out....

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

Image
              *           *      *      *        *       *          *         *              * Program: import java.util.Scanner; public class practical10 {     public static void main(String[] args)     {         int i, j, k;         Scanner scan = new Scanner(System.in);         int no = scan.nextInt();         for (i = 0; i < no; i++)         {             for (j = (no / 2) + 1; j >= i; j--)         ...

Practical 9 : Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows:

Image
                  s                s     t              s    t     r          s     t     r    e       s     t    r      e   a    s     t    r     e      a   m Program: public class practical9    {     public static void main(String[] args)     {         int i, j, k;  String str = "Stream";         for (i = 0; i < str.length(); i++)       {             for (j = (str.length() / 2) + 1; j >= i; j--)  ...

Practical 8 : Create a class which ask 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.

Image
Program: import java.util.Scanner; public class practical8 {     public static void main(String[] args)     {         System.out.println("Enter the word 'quit' to end this program.");         String str;         int x = 0, A = 0, E = 0, I = 0, O = 0, U = 0;         char ch;         Scanner in = new Scanner(System.in);         while (x < 1) {             str = in.next();             if (str.equals("quit")) {                 x++;         ...

Practical 7: Write a program to find that given number or string is palindrome or not.

Image
Program: import java.util.*; class practical7 {    public static void main(String args[])    {       String original, reverse = "";       Scanner in = new Scanner(System.in);       System.out.println("Enter a string to check if it is a palindrome : ");       original = in.nextLine();       int length = original.length();       for ( int i = length - 1; i >= 0; i-- )          reverse = reverse + original.charAt(i);       if (original.equals(reverse))          System.out.println("Entered string is a palindrome.");       else          System.out.println(...