您好,欢迎访问三七文档
Java程序:⑴JOptionPane.showMessageDialog(newFrame.getContentPane(),弹出的是消息提示框!,系统信息,JOptionPane.INFORMATION_MESSAGE);JOptionPane.showMessageDialog(newFrame.getContentPane(),弹出的是警告提示框!,系统信息,JOptionPane.WARNING_MESSAGE);JOptionPane.showMessageDialog(newFrame.getContentPane(),弹出的是错误提示框!,系统信息,JOptionPane.ERROR_MESSAGE);JOptionPane.showMessageDialog(newFrame.getContentPane(),弹出的是询问提示框!,系统信息,JOptionPane.QUESTION_MESSAGE);intoption=JOptionPane.showConfirmDialog(null,文件已修改,是否保存?,保存文件?,JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE,null);switch(option){caseJOptionPane.YES_NO_OPTION:{saveAsFile();break;}caseJOptionPane.NO_OPTION:System.exit(0);}①:消息框的输出importjavax.swing.*;publicclasstext{publicstaticvoidmain(String[]args){JOptionPane.showMessageDialog(null,title,提示框,JOptionPane.INFORMATION_MESSAGE);//JOptionPane.showMessageDialog(null,提示框,title,JOptionPane.WARING_MESSAGE);//System.out.println(你好,主人);}}②:系统时间的显示importjava.util.Date;publicclasstext{publicstaticvoidmain(String[]args){Dated=newDate();System.out.println(d);}}③:Java中求圆的面积importjava.util.Scanner;publicclasstext{publicstaticvoidmain(String[]args){doublea,r;Scanners=newScanner(System.in);r=s.nextDouble();a=3.14*r*r;System.out.println(圆的面积=+a);}}④:importjava.util.*;publicclasstext{publicstaticvoidmain(String[]args){doubler;System.out.print(输入圆的半径:);Scanners=newScanner(System.in);r=s.nextDouble();doubleS=Math.PI*r*r;System.out.print(面积为:+S);}}④:猜数小游戏importjavax.swing.*;publicclassbox{publicstaticvoidmain(String[]args){inti=10;Strings=JOptionPane.showInputDialog(null,Inputi,InputBox,JOptionPane.QUESTION_MESSAGE);intj=Integer.parseInt(s);if(ji)JOptionPane.showMessageDialog(null,”正确,MessageBox,JOptionPane.INFORMATION_MESSAGE);}}⑤:随机数的输出importjava.util.Random;publicclassrandom{publicstaticvoidmain(String[]args){doublei=Math.random();intj=(int)(i*100);System.out.println(j);}}⑥:随机数的输出importjava.util.Random;publicclassrandom{publicstaticvoidmain(String[]args){Randomr=newRandom();inti=r.nextInt();i=i%100;if(i0)i=-i;System.out.println(i);}}
本文标题:Java程序
链接地址:https://www.777doc.com/doc-2881194 .html