Posts

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)                 {                 ...