Posts

Showing posts from February, 2022

Write a program to create a room class, the attributes of this class is roomno, roomtype, roomarea and ACmachine. In this class the member functions are setdata and displaydata.

Image
  /* Write a program to create a room class, the attributes of this class is roomno, roomtype, roomarea and ACmachine. In this class the member functions are setdata and displaydata. */ class Room {            int roomno;     String roomtype;     float roomarea;     boolean ACmachine;     void setdata(int no,String type,float area,boolean ac)     {         roomno = no;         roomtype = type;         roomarea = area;         ACmachine = ac;     }     void displaydata()     {         System.out.println("Room Number Is : " + roomno);         System.out.println("Room Type Is : " + roomtype);         System.out.println("Room Area Is : " + roomarea);         String machine = (ACmachine) ? "Yes" : "No";     ...

Java Program to print the duplicate elements of an array

Image
 /* Java Program to print the duplicate elements of an array */ import java.util.*; class Twentythree {     public static void main(String arg[])     {         Scanner in = new Scanner(System.in);         System.out.print("Enter Array Size : ");         int n = in.nextInt();         int arr[] = new int[n];         for(int i=0; i<n; i++)         {             System.out.print("Enter Number of Arr[" + i + "] : ");             arr[i] = in.nextInt();         }         for(int i=0; i<n; i++)         {             System.out.println("Arr[" + i + "] Is : " + arr[i]);         }         System.out.print("\nDuplicate Value Is : ");         fo...

Write a program to check if two given String is Anagram of each other.

Image
 /* Write a program to check if two given String is Anagram of each other.  Your function should return true if two Strings are Anagram, false  otherwise. A string is said to be an anagram if it contains the same characters and same length, but in a  different order, e.g. army and Mary  are anagrams. You can ignore cases for this problem. */ import java.util.*; class Twentytwo {     public static void main(String arg[])          {         int a , b ;         Boolean f=true;         Scanner obj= new Scanner(System.in);         System.out.print("Enter 1st String : ");         String s1 = obj.nextLine();         System.out.print("Enter 2nd String : ");         String s2= obj.nextLine();         if( s1.length() == s2.length())         {     ...

Write a program to remove duplicates from an array in Java

Image
 /* Write a program to remove duplicates from an array in Java */ import java.util.*;   class Twentyone {       public static void main(String arg[])      {           int n , add = 0;         Scanner in = new Scanner(System.in);         System.out.print("\nEnter Array Size : ");         n = in.nextInt();         int a[] = new int[n];         for(int i=0; i<n; i++)          {             System.out.print("Enter Number arr[" + i + "] : ");             a[i] = in.nextInt();             add =add + a[i];         }         int arr[] = new int[add];         System.out.println("\nAfter Removing Duplicates Numbers : ");       ...

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Image
 /* Design and Develop a java program to read marks of a student and print  the total and average of marks using scanner class. */ import java.util.*; class Twenty {     public static void main(String arg[])     {         int n,sum=0,avg;         Scanner in = new Scanner(System.in);         System.out.print("\n Enter number Of Subjects : ");         n = in.nextInt();         int a[] = new int[n];         for(int i=0; i<n; i++)         {             System.out.print("Enter Mark value [" + (i+1) + "] : ");             a[i] = in.nextInt();             sum = sum + a[i];         }         System.out.println("\nTotal Marks Is : " + sum);         avg = sum / n;     ...

Write a Java program that checks whether a given string is a palindrome or not.

Image
 /* Write a Java program that checks whether a given string is a palindrome  or not.  Ex: MADAM is a palindrome? */ import java.util.*; class Nineteen {     public static void main(String arg[])     {         String str, r = "";         Scanner in = new Scanner(System.in);         System.out.print("\n Enter String : ");         str = in.nextLine();         for (int i=str.length()-1 ; i>=0 ; i--)         {             r = r + str.charAt(i);         }         if (str.equals(r))         {             System.out.println("'" + str + "' Is A Palindrome");         }         else         {             System.out.println("'" + str + "...

Write a Java program that prompts the user for an integer and then printsout all the prime numbers up to that Integer?

Image
 /* Write a Java program that prompts the user for an integer and then  printsout all the prime numbers up to that Integer? */ import java.util.Scanner;  class Eighteen {     public static void main(String arg[])     {         int no,prime;           Scanner input = new Scanner(System.in);         System.out.print("\n Enter Number here: ");         no = input.nextInt();          System.out.print("\n ");         for(int i=2;i<no;i++)         {                 prime=0;             for(int j=2;j<i;j++)             {                 if(i%j==0)                 {                 ...

Write a Java program to replace a string "python" with "java" and "java" with "python" in a given string.

Image
 /* Write a Java program to replace a string "python" with "java" and "java" with "python" in a given string. Expected Output: Input the string: python is more propular than java New string: java is more propular than python */ import java.util.*; class Seventeen  {     public static void main(String arg[])     {                 Scanner in = new Scanner(System.in);         System.out.print("\n Enter any String for java or python : ");         String str = in.nextLine();         str = str.replaceAll("java", "py_thon");         str = str.replaceAll("python", "java");         str = str.replaceAll("py_thon", "python");         System.out.println("\n New String : " + str);     } } More Information on our channel  Programmer Community please like , share and subscribe to get notificatio...

Write a Java program to take the last three characters from a given string and add the three characters at both the front and back of the string.

Image
 /* Write a Java program to take the last three characters from a given string and add the three characters at both the front and back of the string.  String length must be greater than three and more. Test data: "Python" will be "honPythonhon" Sample Output: honPythonhon */ import java.util.*;  class Sixteen  {     public static void main(String arg[])     {            Scanner in = new Scanner(System.in);         System.out.print("\n Enter String : ");          String str = in.next();         String ch = str.substring(str.length() - 3);         System.out.println("\n " + ch + str + ch);     } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to capitalize the first letter of each word in a sentence.

Image
 /*  Write a Java program to capitalize the first letter of each word in a sentence. Sample Output: Input a Sentence: the quick brown fox jumps over the lazy dog. The Quick Brown Fox Jumps Over The Lazy Dog.  */ import java.util.*; class Fifteen {   public static void main(String arg[])     {         Scanner in = new Scanner(System.in);         System.out.print("\n Enter String hear: ");         String str = in.nextLine();         str = " " + str;         String s = "";         for(int i=0; i<str.length(); i++)         {             char ch = str.charAt(i);             if(ch == ' ')             {                 s = s + ch;                 i++; ...

Write a Java program to create a spiral array of n * n sizes from a given integer n.

Image
 /*  Write a Java program to create a spiral array of n * n sizes from a given integer n. Expected Output: Input a number: 5 Spiral array becomes: 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 */ import java.util.*; class Fourteen { public static void main(String arg[]) { Scanner obj = new Scanner(System.in); int no, a=1, i, j; System.out.print("\n Enter any number to get spiral array : "); no = obj.nextInt(); System.out.println(); int arr[][] = new int[no][no]; for (i=0 ; i<=no/2 ; i++)   { for (j=i; j<no-i ; j++ )  { arr[i][j] = a; a++; } for(j=i+1 ; j<no-i ; j++) { arr[j][no-i-1] = a; a++; } for(j=no-i-2 ; j>=i ; j--) { arr[no-i-1][j] = a; a++; } for(j=no-i-2 ; j>i ; j--) { arr[j][i] = a; a++; } } for (i=0 ; i<no ; i++)  { for (j=0; j<no ; j...

Write a Java program to test if a given number (positive integer ) is a perfect square or not.

Image
 /* Write a Java program to test if a given number (positive integer ) is a perfect square or not. Expected Output: Input a positive integer: 6 Is the said number perfect square? false */ import java.util.*; class Thirteen { public static void main(String arg[]) { Scanner obj = new Scanner(System.in);  int no, a, flag=0; System.out.print("\n Enter any positive number to cheak \n that number is perfect square or not : "); no = obj.nextInt(); outer: for (int i=1 ; i<=no ; i++ )  { a = i * i; if(no == a) { flag = 1; break outer; } } if(flag == 1) { System.out.println("\n\t => Enterd number is perfect square <="); } else { System.out.println("\n\t => Enterd number is not perfect square <="); } } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will comin...