Home / JAVA (page 5)

JAVA

Java program to print first 20 fibonacci numbers

Program for fibonacci series

Fibonacci Numbers are the numbers in series which follow the concept that every next number is the sum of previous two numbers. But then which were the first two numbers. They are initially taken 0,1 . Series: 0,1,1,2,3,5,8,13,21,34,55,89….. Also See: c program to print first 20 fibonacci numbers

Read More »

Java program to change lower case to upper case and vice versa

This is a program to alter the case of all characters in a string given as a input. So small letter becomes capital and vice-versa, no change to other symbols or numbers is made. Thus upper case changes to lower case and lower to upper. Example:- HellO WoRlD OUTPUT:- hELLo wOrLd import java.io.*; class prog5 { void main()throws IOException { ...

Read More »

What is Java and why is java needed?

The question what is Java is now almost an absurd one because it has emerged as the top 10 computer discoveries in the year 1995 and ever since. Java is an object oriented programming language that was developed by James Gosling at SUN Microsystems. The writing of this language started in June, 1991 by Mike Sheridan, Patrick Naughton and James ...

Read More »

Character array c / character array java

Character array in c and character array in java can be implemented in two ways:   1. Character array using pointers:  Using pointer you can assign a string value to a character array however it will still work as an character array not as a string. The pointer will point to the first index of your assigned string. char *arr=”hello”;      or char ...

Read More »

How to Null a string or empty a string array

Null a String/ Empty a string array Null a string in C using pointer string or array string. Many times the string is nullified assigning arr[0]=’\0′ but this will not nullify the array as only the first index will be NULL.   1. Null a string using pointer string. char *ptr="hello"; printf("%s" , ptr); *ptr='\0'; printf("\n %s  and  %s ",ptr,ptr+1); ...

Read More »

program in Java/ Bluej to display the present date and the date after N days

Q. Write a program to input the number of days, year and integer N and display the present date and date after N Days. class iscdate2 { void calc(int yr,int cd,int n1) { String m[]={"jan","feb","march","april","may","june","july","august","september","october","november", "december"}; { int a[]={31,29,31,30,31,30,31,31,30,31,30,31}; int b[]={31,28,31,30,31,30,31,31,30,31,30,31}; int t=0,d,c,i; c=(n1/30+1); for(i=0;i<c;i++) { if(yr%4==0) t+=a[i]; else t+=b[i]; if(t>n1) { if(n1>30) d=n1-t+a[i]; else d=n1; if(cd==1) System.out.println("present date:"+d+m[i]+yr); else System.out.println("date after"+cd+"day ...

Read More »

Java program for producing prime numbers for given range

Program to print all prime numbers between 100 to 10000 or whatever given range.   class prime { public static void main() { int i,j,k; for(i=101;i<10000l;i++) //here you can give your own range { k=0; for(j=2;j<i;j++) { if(i%j==0) k++; } if(k==0) System.out.print(i+" "); } } } OUTPUT: Tags: bluej program to find the prime numbers between 100 to 1000, prime ...

Read More »

Program to find difference between two dates java

Java program to find out the number of days elapsed between two dates. Java program to find out the difference between two dates given as DD-MM-YY. import java.io.*; class datedif { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the first date:"); System.out.print("enter the days="); int d1=Integer.parseInt(br.readLine()); System.out.print("enter the month="); int m1=Integer.parseInt(br.readLine()); System.out.print("enter the year="); int ...

Read More »