Skip to main content

Posts

print month of any year as inputted by the user in java

import java.io.*; class Calendar { public static void main(String a[])throws Exception {  ab obj =new ab(); obj.find(); } } class tmp { int d,m,y,mo[]={0,31,28,31,30,31,30,31,31,30,31,30,31},cal=0,i; void input()throws Exception { DataInputStream dd= new DataInputStream(System.in); System.out.println("Enter a day"); d=Integer.parseInt(dd.readLine()); System.out.println("Enter a month"); m=Integer.parseInt(dd.readLine()); System.out.println("Enter a year"); y=Integer.parseInt(dd.readLine()); if(check()==0) {System.out.println("Wrong date"); System.exit(0); } else {cal=calculate(); System.out.println("Days passed" +" "+cal); } } private int check() { int che=1; if((y<=0)||m>12||d>31||y<=0||m<=0||(leap()==0 &&m==2&&d>28)) che=0; else che=1; return che; } private int leap() { if(y%100==0) { if(y%400==0) return (1); return(0); } else if(y%4==...

Honolulu Injury Lawyer

Honolulu Injury Lawye r I always prefer   Honolulu Injury Lawyer   They've got a big dream team with lots of smooth talking attorneys.  They give free consultation and free preliminary case evaluation  and so many other excellent services  that other firms can never provide in their lifetime  

Transpose elements in an array

import java.io.*; class Transpose { public static void main(String a[])throws Exception { tmp ob=new tmp(); ob.transpose(); } } class arr { int a[][],n,i,j,k,l,m; public void inp()throws Exception { DataInputStream dd= new DataInputStream(System.in); System.out.println("Enter a value"); n=Integer.parseInt(dd.readLine()); a=new int[n][n]; for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=Integer.parseInt(dd.readLine()); } public void display() { for(i=0;i<n;i++) { for(j=0;j<n;j++) System.out.print(a[i][j]+"\t"); System.out.println(); } System.out.println(); System.out.println(); } } class tmp extends arr { public void transpose()throws Exception { super.inp(); super.display(); j=0; for(i=0;i<super.n;i++) {j=j+1; for(;j<super.n;j++) ex(i,j,j,i); display(); } } private void ex(int b,int c,int d,int e) { int t=super.a[b][c]; System.out.println(super.a[b][c]); System.out.println(super.a[d][e]); super.a...

Search a Array inside another array using inheritance

import java.io.*; class Search { public static void main(String a[])throws Exception { tmp ob=new tmp(); ob.check(); } } class arr { int a[][],n,i,j,k,l,m; public void inp()throws Exception { DataInputStream dd= new DataInputStream(System.in); System.out.println("Enter a value"); n=Integer.parseInt(dd.readLine()); a=new int[n][n]; for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=Integer.parseInt(dd.readLine()); } public void display() { for(i=0;i<n;i++) { for(j=0;j<n;j++) System.out.print(a[i][j]+"\t"); System.out.println(); } System.out.println(); System.out.println(); } } class tmp extends arr { int a[][],n,i,j,k,l,ch=1; public void inp()throws Exception { super.inp(); DataInputStream dd= new DataInputStream(System.in); System.out.println("Enter a value"); n=Integer.parseInt(dd.readLine()); a=new int[n][n]; for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=Integer.parseInt(dd.readLine()); } publi...

FINDING MISSING ELEMENTS IN A STRING

import java.io.*; import java.lang.*; class Misord { public static void main(String args[])throws IOException { check chk= new check(); String str1=chk.input(); String str4=chk.ord(str1); chk.mis(str4); } } class check { public String input()throws IOException { String x = " "; System.out.println("Enter the String"); DataInputStream in = new DataInputStream(System.in); x= in.readLine(); return(x); } public String ord(String str1) { char ch=' '; String str2=str1; String str3=" "; int l=str2.length(); int i,j; for(i=65;i<=90;i++) { for(j=0;j<=l-1;j++) { ch = str2.charAt(j); { if(((int)ch==i)||((int)ch==i+32))//change here has been done { str3=str3+ch; str3=str3.trim(); } } } } System.out.println(str3); return(str3); } public void mis(String str4) { String str5=str4.trim(); String s1=" "; int i=0,j=0,f=0,p=0; int l=str5.length(); System.out.println(l); for(i=65;i<90;i++) { p=0;...

Program in java to extract words and print the words starting with a inputted character

import java.io.*; import java.lang.*; class Ser { public static void main(String args[])throws Exception { DataInputStream dd= new DataInputStream(System.in); System.out.println("enter a string "); String str=dd.readLine(); System.out.println("enter a character"); char ch=(char)System.in.read(); s o =new s(); if(o.extract(str,ch)==true) o.display(); else System.out.println("NOT FOUND"); } } class s { String s2=""; public boolean extract(String str,char ch2) { str=str+" "; String s3=""; boolean b=false; int i; for(i=0;i<str.length();i++) { char ch= str.charAt(i); if(ch != ' ') s3=s3+ch; else { if(s3.charAt(0)==ch2)    { b=true; s2=s2+" "+s3;     } s3="";  } } return b; } public void display() { System.out.println(s2); } }

StringBuffer in java

import java.io.*; class a { public static void main(String[] args) { StringBuffer s=new StringBuffer(); System.out.println(s.capacity()); System.out.println(s.length()); StringBuffer s1=new StringBuffer(100); System.out.println(s1.capacity()); StringBuffer s2=new StringBuffer("npgc"); System.out.println(s2); System.out.println(s2.length()); System.out.println(s2.capacity()); } } OUTPUT 16 0 100 npgc 4 20