请用JAVA语言实现函数并对之进行测试
x (x<1)
y= 2x-1 (1<=x<10)
3x-11 (x>=10
2.使用java.util.Calendar类制作一个程序用“YYYY/MM/DD HH:MM:SS”格式显示当前日期和时间。
[此贴子已经被作者于2005-5-10 14:19:58编辑过]
----------------解决方案--------------------------------------------------------
晕第一题用Swich()函数或者其他函数就可以做,很简单!
第二题,偶不会,偶学Java才不久
----------------解决方案--------------------------------------------------------
[CODE]
import java.util.Calendar;
public class DisplayDateTime { public static void main(String args[]) { Calendar c=Calendar.getInstance(); System.out.println(c.get(Calendar.YEAR) + "/" + c.get(Calendar.MONTH) + "/" + c.get(Calendar.DAY_OF_MONTH) + " " + c.get(Calendar.HOUR_OF_DAY)+ ":" + c.get(Calendar.MINUTE)+ ":" + c.get(Calendar.SECOND)); }
}
[/CODE]----------------解决方案--------------------------------------------------------
多谢版主,觉得语言真是难学
----------------解决方案--------------------------------------------------------
没什么,自己多写多看多领悟,我都是自学的。如果你学不会说明你可能还不够努力
----------------解决方案--------------------------------------------------------
第二道题 小应用程序 import java.awt.*; import java.util.*;
public class Watch extends javax.swing.JApplet { private Color butterscotch = new Color(255, 204, 102); private String lastTime = "";
public void init() { setBackground(Color.black); }
public void paint(Graphics screen) { Graphics2D screen2D = (Graphics2D)screen; Font type = new Font("Monospaced", Font.BOLD, 20); screen2D.setFont(type); GregorianCalendar day = new GregorianCalendar(); String time = day.getTime().toString(); screen2D.setColor(Color.black); screen2D.drawString(lastTime, 5, 25); screen2D.setColor(butterscotch); screen2D.drawString(time, 5, 25); try { Thread.sleep(1000); } catch (InterruptedException e) { // do nothing } lastTime = time; repaint(); } }
----------------解决方案--------------------------------------------------------
楼上的设计真是巧妙!!!
----------------解决方案--------------------------------------------------------