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 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 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 more2) Write a Java program that converts given String into Lower and Upper case Strings.
class loweruppercase { void lower(String s) { System.out.println(s.toLowerCase()); } void upper(String s) { System.out.println(s.toUpperCase()); } public static void main(String as[]) { System.out.println("string lower and upper case program"); loweruppercase ob=new loweruppercase(); ob.lower("Welcome …
Read moreimport java.util.*; class datedemo { public static void main(String as[]) { Date d=new Date(); System.out.println("today's date and time:"+d); } } output: today's date and time:Wed Dec 09 21:00:30 IST 2020
Read more