Posts

Program to tell the date after some days from the beginning of the year.

Write a program to input a long integer date not less than 5 digits. If data is <5 then prompt the user to reenter. In the input last four digits represent the year and the remaining digits of the number as the days from the starting from the year. Your program displays actual data(using no. of days extracted) followed by month name and year. Leap years are to be taken care of and days may exceed >365 that is the next year may appear. Example: 272008 Output: 27 January 2008 Example: 802005 21 March 2005 Example: 7342005 4 January 2007 import java.io.*; public class YearDate { public void work() throws IOException { String yr, ds, s; long yrs, days, date; yr = ds = s = ""; yrs = days = date = 0; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); for (;;) { System.out.print("Enter the number: "); s = br.readLine(); date = Long.parseLong(s); yr = s.substring(s.length() - 4); ds = s.substring(0, s.length() - 4); yrs = Long....
Write a program to input a complete date with its day and the output will show the day of the first day of the year of the input year. Example: 21-4-2018 Saturday Output: Monday import java.io.*; public class YearDay { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the date: "); int dt=Integer.parseInt(br.readLine()); System.out.print("Enter the month: "); int mn=Integer.parseInt(br.readLine()); System.out.print("Enter the year: "); int yr=Integer.parseInt(br.readLine()); System.out.print("Enter the day:  "); String day=br.readLine(); int arr[]= {31,28,31,30,31,30,31,31,31,30,31,30}; String arrM[]= {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}; if(yr%4==0) arr[1]=29; int ct=0; for(int ...

Input some names and then print the names vertically and side by side.

Image
Code Output /**  * Write a program to input some names >2 and <=9 and print it vertically side by side.  * Input: Ankur  Chiranjan  Mack  * output:  A C M  * N H A  * K I C  * U R K  * R A  *   N  *   J  *           A  *   N  */ package stringFun; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class stringFun { String a[]; int lenM; stringFun() { lenM = 0; } private void fnInput() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the number of names:  "); int s = Integer.parseInt(br.readLine()); a = new String[s]; for (int x = 0; x < s; x++) a[x] = br.readLine(); br.close(); } private void fnSort() // This method finds out the length of the longest ...

Saddle Point

Given a matrix of n x n size, the task is to find saddle point of the matrix. A saddle point is an element of the matrix such that it is the minimum element in its row and maximum in its column. Examples: Input: Mat[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Output: 7 7 is minimum in its row and maximum in its column. Input: Mat[3][3] = {{1, 2, 3}, {4, 5, 6}, {10, 18, 4}} Output: No saddle point import java.io.*; class SaddlePoint { public void displayPoint() throws IOException { BufferedReader br= new BufferedReader( new InputStreamReader(System.in)); System.out.print( "Enter no of rows: " ); int r=Integer.parseInt(br.readLine()); System.out.print( "Enter no of columns: " ); int c=Integer.parseInt(br.readLine()); int [][]arr= new int [r][c]; int stR= 0 ; //To store the row index of ...

PSEUDO Series

You are given a sequence of N integers, which are called as pseudo-arithmetic sequences (sequences that are in arithmetic progression). Sequence of N integers: 2, 5, 6, 8, 9, 12. We observe that 2 + 12 = 5 + 9 = 6 + 8 = 14. The sum of the above sequence can be calculated as 14 × 3 = 42. For a sequence containing an odd number of elements, the rule is to double the middle element. For example, for a sequence of N integers: 2, 5, 7, 9, 12. We have 2 + 12 = 5 + 9 = 7 + 7 = 14. 14 × 3 = 42 (middle element = 7). import java.io.BufferedReader; import java.io.InputStreamReader; class PSEUDO {      static int p[], sum[], n;      static boolean getV;     PSEUDO( int x) {         getV = true ;         n = x;          if (n % 2 != 0 )         ...

Combine two strings with common alphabets and without repetition.

/**  *A class STRICOM contains two strings and creates a new string using the common characters  *present in both the strings(without repetition)  *Example     "chinese"    and    "checkers"  *New String:   "ches"  */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class STRICOM { static String stA, stB; STRICOM(String a, String b) { stA = a; stB = b; } int fnLen(String S) { return S.length(); } String fnCommon() { String newSt = ""; int len2 = fnLen(stB); for (int a = 0; a < stA.length(); a++) { inner: for (int b = 0; b < len2; b++) { char ch1 = stA.charAt(a); char ch2 = stB.charAt(b); if (ch1 == ch2) { newSt += ch1; break inner; } } } return newSt; } void fnShow() { System.out.println("Inputted Strings\n" + stA + "\t\t" + stB); Stri...