source file name: Revno.C #include<stdio.h> int main() { long n,d1,d2,d3,d4,d5; long revno; //clrscr(); printf("\n enter any 5 digit number: "); scanf("%ld",&n);// 12345 d1=n%10; // d1= 12345%10=5 n=n/10; // 12345/10=1234 d2=n%10; // 1234%10=4 d2=4 n=n/10; …
Read more12) Write a C program to obtain the sum of the first and last digit of any Four digit number.
source file name: SumDig1_4.C #include<stdio.h> int main() { int n,d1,d2,d3,d4,d5; int sum=0; //clrscr(); printf("\n enter any only 4 digit number: "); scanf("%d",&n); d1=n%10; n=n/10; d2=n%10; n=n/10; d3=n%10; n=n/10; d4=n%10; sum=d1+d4; printf("\n sum of first and fourth digit=%d…
Read more11) Write a C program to convert Fahrenheit degrees temperature into centigrade degrees.
source file name: FarToCel.C #include<stdio.h> int main() { float F,C; //clrscr(); printf("\n Enter Farhenheit temp.: "); scanf("%f",&F); C=(5*(F-32))/9; printf("\n Centigrade temp.=%f",C); //getch(); return 0; } output:
Read more5) Write a Java program that displays power value 1 to 10 base 2 , using Math class pow().
source file name: mathdemo3.java class mathdemo3 { public static void main(String as[]) { System.out.println("power values of 2 base program "); for(int b=1;b<=10;b++) System.out.println(" 2 raised to "+b+" is: "+Math.pow(2,b)); } } output: D:\JavaPrograms\Misc>javac mathdemo3.jav…
Read more15) Write a java program on StringTonizer traversing that adds all double numbers accepted by one String type.
source file name: strtokendemo.java import java.util.*; import java.text.*; class strtokendemo { public static void main(String as[]) { System.out.println("String Tokenizer class program"); String s="123.50 2.5 l6.3f 520 10.4 10l.25f 10.2505"; System.out.println(" list of tokens: "); St…
Read more14) Write a Java Program on Vector traversing that adds all numbers accepted by command line and display sum of these numbers.
source file name: enumdemo.java import java.util.*; class enumdemo { public static void main(String as[]) { System.out.println("Vector demo program"); Vector v=new Vector(); Object ob; for(int i=0;i<as.length;i++) { ob=new String(as[i]); v.add(ob); } System.out.println("vector v="+v); Stri…
Read more13) Write a java program on vector class and its methodslike add(),remove(),insertElement() and toArray()
source file name: vectordemo1.java import java.util.*; class vectordemo1 { public static void main(String as[]) { System.out.println("vector demo program"); Vector v1=new Vector(); String s1="one"; String s2="two"; Integer il=new Integer(100); Float f=new Float(2.53f); v1.add(s1); v1.ad…
Read more12) Write a java Program that accepts runtime rows and column of two dimensional array and display this 2D array.
source file name: matrix.java import java.io.*; import java.util.*; public class matrix { public static void main(String[]args)throws IOException{ int[][]dim=new int[2][2]; BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the rows of ma…
Read more10) Write a Java program that finds prime numbers between given range provided by user at Command line.
source file name: rangeprimenocmd.java class rangeprimenocmd { void prime(int n) { int d=2; while(d<n) { if(n%d==0) break; else d++; } if(d==n) System.out.print(n+" "); } public static void main(String args[]) { rangeprimenocmd p=new rangeprimenocmd(); int n1=Integer.parseInt(args[0]); int n2=Integer.pars…
Read more11) Write an Java program that reads string from the console and program should reverse the sequence of characters.
source file name: ReverseDemo1.java import java.io.*; class ReverseDemo1 { public static void main(String args[]) throws IOException { String str=""; try { DataInputStream dis=new DataInputStream(System.in); System.out.println("enter any string "); str=dis.readLine(); } catch(Exception e) { Syste…
Read more10) Write a java program that sorts student names in alphabetically order where names are accepted from command line.
source file name: stringdemo3.java class stringdemo3 { public static void main(String as[]) { String[] students=new String[as.length]; String temp=null; for(int i=0;i<as.length;i++) students[i]=as[i];//command line students name stores in students array System.out.println("givens student list:"); for(in…
Read more9) Write a Java program on String class functions like equality of strings, index value of char inside string, replacing, deleting and trim characters.
source file name: stringdemo2.java class stringdemo2 { public static void main(String as[]) { System.out.println("string demo program"); System.out.println("upper case conversion: "+"One".toUpperCase()); System.out.println("lower case conversion: "+"Two".toLowerCase(…
Read more8) Write a Java program to illustrate String handling functions like concat, length, toLowerCase, toUpperCase, equals.
Write a Javaprogram to illustrate Java string handling for following functions: Concatenation of “dbjcollege”,”chiplun”, Reverse of “12721”. Determine whether the two strings:”dbjcollege”,”DBJCollege” are equal or not? Convert the string “Hello World” to uppercase. Convert the string “Let Us C”to lowercase.Length of…
Read more2) Write a Java program that download file from the Internet and either copy it as a file on local machine , or output it to the screen.
source file name: DownloadFileDemo.java import java.io.*; import java.net.*; class DownloadFileDemo { public static void main(String[] dbj) { InputStream in=null; OutputStream out=null; try { URL url=new URL(dbj[0]); in=url.openStream(); if(dbj.length==2) out=new FileOutputStream(dbj[1]); else out=System.o…
Read more7) Write a Java program that converts any decimal integer number into binary and octal and hexadecimal equivalents using Integer class methods.
source file name: convdemo.java import java.io.*; class convdemo { public static void main(String as[]) { int n=1; System.out.println("enter value:"); try{ DataInputStream dis=new DataInputStream(System.in); String s=dis.readLine();//accept input number from user n=Integer.parseInt(s); System.out.println(&…
Read more6) Write a Java program that displays square and cube values of any 10 random numbers using Math class method random.
source file name: mathdemo4.java class mathdemo4 { public static void main(String as[]) { System.out.println("squares and cubes of any 10 random numbers: "); System.out.println("n\tsquare\tcube"); for(int b=1;b<=10;b++) { int n=(int)(20*Math.random()); int sq=n*n; int cube=n*n*n; System.out.p…
Read more4) Write a Java program that display square roots of 1 to 10 numbers using Math class sqrt method.
source file name: mathdemo2.java class mathdemo2 { public static void main(String as[]) { System.out.println("square root program"); for(int b=1;b<=10;b++) System.out.println("square root of "+b+" is: "+Math.sqrt(b)); } } output: D:\JavaPrograms\Misc>javac mathdemo2.java D:\JavaPr…
Read more3) Write a java program on Math class methods sqrt, pow, min, max, ceil, floor, rint, sin, cos, tan.
source file name: mathdemo1.java class mathdemo1 { public static void main(String as[]) { System.out.println("square root value:"+Math.sqrt(36)); System.out.println("power value:"+Math.pow(5,4)); System.out.println("maximum between 2 numbers:"+Math.max(100,50)); System.out.println(&quo…
Read more1) Write a Java program that finds IP address of different websites and Computers.
source file name: InetAddressDemo.java import java.io.*; import java.net.*; class InetAddressDemo { public static void main(String[] args) { try { InetAddress ip1=InetAddress.getByName("sjnprogramming.blogspot.com"); InetAddress ip2=InetAddress.getLocalHost(); InetAddress[] ip=InetAddress.get…
Read moreSingle Inheritance source file name: singledemo.java class A { void sum(int a, int b) { System.out.println("addition ="+(a+b)); } } class B extends A { void sub(int a, int b) { System.out.println("subtraction ="+(a-b)); } } class singledemo { public static void main(String as[]) { System.out.prin…
Read moreHierarchical Inheritance : source file name: Hierarchicaldemo.java class A { void sqcube(int n) { int sq=n*n; int c=n*n*n; System.out.println("square="+sq+" cube="+c); } } class B extends A { void add(int a,int b) { System.out.println("sum="+(a+b)); } void sub(int a,int b)…
Read moreMultilevel Inheritance: Source file Name: Multileveldemo.java class A { void sum(int a,int b) { System.out.println("sum="+(a+b)); } } class B extends A { void sub(int a,int b) { System.out.println("substract="+(a-b)); } } class C extends B { void sqcube(int n) { int sq=n*n; int c=…
Read more6) Write a Java Program that reads a file, converts each tab character to a space character, and writes its output to another file , both files passed through CMD line.
source file name: TabsDemo.java import java.io.*; public class TabsDemo { public static void main(String[]args) { File infile=new File(args[0]); File outfile=new File(args[1]); FileReader ins=null; FileWriter fos=null; int cnt=0; try{ ins=new FileReader(infile); fos=new FileWriter(outfile); int ch; while((ch=ins.r…
Read more5) Write Java Program writes the first 15 numbers of the Fibonacci series to a file and reads this data from a file and display it , files names passed through CMD line.
Write an application that writes the first 15 numbers of the Fibonacci series to a file .Write a second application that reads this data from a file and display it. For both application, specify, the name of the file as command-line argument. source file name: fibfilewrite.java import java.io.*; class fibfilewrit…
Read more4) Write a Java program that illustrate Method Over-riding concept using Bond and ConvertibleBond classes.
Write a Java program that illustrate Method Over-riding concept. Class Bond is extended by ConvertibleBond. Each of these classes defines a display() method that outputs the string 'Bond" or "ConvertibleBond" respectively. Declare an array to hold six Bond objects. Initialize the elements of the…
Read more3) Write a Java program that checks numbers and display different messages using Method overriding concept.
Create a class called Disp containing the instance variable n , to display the following classes message "I am Good" whenever n<0 and the message "I am Great" otherwise . This class is inherited by another class Display containing the instance variable n. This class contains a method that…
Read more3) Write a Java program that finds GCD and LCM using Inheritance , Overloading methods and super() terms.
source file name: InheritanceOverload.java class A { int x; public A(int a) { x=a; } public void display() { System.out.println("class A"); } } class B extends A { int y; public B(int a,int b) { super(a); y=b; } public void display() { int gcd=gcd(); int lcm=lcm(gcd); System…
Read more10) write a Java program on playing Cards using 2 classes and face() , color() methods.
Write a java program consisting of following classes. A class number stores nine cards number from 2 to 10 using nine_no() method and face cards are stored using instance variable.A method code() determine the card from the suit with number and the color of the card.There is another method called face() to find t…
Read more9) Write a Java program that finds largest integer and smallest integer from 10 given array numbers , program also display 5 elements per line.
Initialize an array of size 10 and find the largest integer and smallest integer in the array. Also to display the array elements 5 per line then display in the new line the largest and smallest integer. class array8 { public static void main(String as[]) { int arr[]={10,5,25,3,-4,100,1000,-10,77,38}; System.out.pri…
Read more8) Write a java program that finds transpose of given matrix with 4*3 order.The program should display both the matrix.
source file name: TransMatrix,java class TransMatrix { public static void main(String as[]) { int A[][]={{10,5,25},{3,-4,10},{1,2,3},{11,12,13}}; int B[][]=new int[3][4]; System.out.println("Matrix A"); for(int i=0;i<4;i++) { for(int j=0;j<3;j++) { System.out.print(A[i][j]+" "); } System.out…
Read more7) Write a java program to display the 3 * 3 matrix, matrix numbers generated by random() method.
source file name: displayarray.java class disparray { public static void main(String as[]) { int A[][]=new int[3][3]; System.out.println("3 * 3 matrix values are generated by random()"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { A[i][j]=(int)(20*Math.random()); } } System.out.println("displa…
Read more6) Write a java program to calculate mean and standard deviation of an array of double numbers.
source file name: MeanStdDemo.java class MeanSD { public double mean(double a[]) { double sum=0.0; for(int i=0;i<a.length;i++) sum=sum+a[i]; return(sum/a.length); } public double std_dev(double a[]) { double x=0.0,sum=0.0; x=mean(a); for(int i=0;i<a.length;i++) sum+=(x-a[i])*(x-a[i]); return (Math.sqrt(sum/a.le…
Read more5) Write a java program to sort the numbers given in an array.The program should display unsorted and sorted array elements
source file name: array1.java class array1 { public static void main(String as[]) { int arr[]={10,5,25,3,-4,100}; System.out.println("Array numbers before sorting"); for(int i=0;i<arr.length;i++) System.out.println(arr[i]); int i,j; for(i=0;i<arr.length;i++) { for(j=0;j<arr.length;j++) { if(arr[i]&…
Read more9) Write a Java program to determine whether they form a triangle and whether triangle is equilateral, isosceles or scalene using 3 numbers.
Write a Java program to by considering three positive integer a,b and c and determine whether they can form three sides of a triangle .if yes determine whether triangle is equilateral, isosceles or scalene. Display the message accordingly. import java.lang.Math; class Triangle { public static void main(String args[]…
Read more8) Write a java program to determine whether they form a triangle and whether triangle is right angle or obtuse or acute using 3 numbers.
Write a java program to by considering three positive integers a,b and c determine whether they can form three sides of a triangle yes determine whether triangle is right angle or obtuse or acute. Display the message accordingly. import java.lang.Math; class RightTriangle { public static void main(String args[]) { i…
Read more7) Write a java program to find and print Reverse number of given number using method. Given number is passed by Command line.
source file name: reversenocmd.java class reversenocmd { void reverse(int no) { int d; long revno=0; while(no>0) { d=no%10; revno=revno*10+d; no=no/10; } System.out.println("reverse number: "+revno); } public static void main(String args[]) { int n=Integer.parseInt(args[0]); reversenocmd ob=new reverse…
Read more6) Write a java program to find the factorial of given number. Compute the factorial value of any number from 1 to 10.
source file name: Factorial.java class Factorial { public static void main(String args[]) { int no=Integer.parseInt(args[0]); int fact=1; for(int i=1;i<=no;i++) fact=fact*i; System.out.println("The Factorial of " + no + " is "+fact); } } output: D:\JavaPrograms\CmdPrograms>javac Factorial.…
Read more5) Write a Java program to input the telephone and number of calls. Calculate and display the bill amount.
Write a java program to input the telephone and number of calls. Calculate and display the bill amount, which include fixed rent of Rs.400.The first 150 calls are free with excess calls are changed at 80 paise each. class PhoneBill { public static void main(String args[]) { int phno=Integer.parseInt(args[0]); int n…
Read more4) Write a Java program to calculate total expenses. A discount of 10% is offered if the quantity purchased is more than 100
source file name: Expenses.java class Expenses { public static void main(String args[]) { int p=Integer.parseInt(args[0]); //conversion of Command line values into integer value if(Integer.parseInt(args[0])>100) System.out.println("The Price is="+(p-(p*10/100))); else System.out.println("The Price…
Read more