Java

How to use time object in java. public class Time1Test { public static void main(String args[]) { Time1 time=new Time1(); System.out.print("The initial universal time is : "); System.out.println(time.toUniversalString()); System.out.print("The initial standard time is : "); System.out.println(time.toString()); System.out.println(); time.setTime(13,27,6); System.out.print("Universal time after setTime is : "); System.out.println(time.toUniversalString()); System.out.print("Standard time after setTime is : "); System.out.println(time.toString()); System.out.println();... Read more »

October 4, 2012 at IST / Language.

Write a program to find which number is maximum. import java.util.Scanner; public class MaximumFinder { public void determineMax() { Scanner input=new Scanner(System.in); double a,b,c,maximum; System.out.print("Enter 3 numbers : "); a=input.nextDouble(); b=input.nextDouble(); c=input.nextDouble(); maximum=max(a,b,c); System.out.println(maximum); } public double max(double a,double b,double c) { double k=0; if (a>b && a>c) k=a; else if(b>c) k=b; else k=c; return... Read more »

October 4, 2012 at IST / Language.

Write a program to draw line from corner to corner in JAVA. import javax.swing.JPanel; import java.awt.Graphics; public class MP4 extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); int width=getWidth(); int height=getHeight(); for(int i=1;i<=15;i++) { g.drawLine(0,0,width,0); width=width+15; height=height+15; } } }  

October 4, 2012 at IST / Language.

Write a program to add two two number in JAVA import javax.swing.JOptionPane; public class MP3 { public static void main(String args[]) { String n1=JOptionPane.showInputDialog("Enter the 1 st number."); String n2=JOptionPane.showInputDialog("Enter the 2 nd number."); double a,b,c; a=Double.parseDouble(n1); b=Double.parseDouble(n2); c=a+b; String message=String.format("the sum of the entered two numbers is %.2f",c); JOptionPane.showMessageDialog(null,message); } }  

October 4, 2012 at IST / Language.

GUI program to show basic input using a dialog box. import javax.swing.JOptionPane; public class MP2 { public static void main(String args[]) { String hobby=JOptionPane.showInputDialog("What is your hobby?"); String message=String.format("Hi i am Piyush and my hobby is %s",hobby); JOptionPane.showMessageDialog(null,message); } }  

October 4, 2012 at IST / Language.