package Chapter1;
//Java.lang包内的所有类都被默认导入在每一个Java程序中
import javax.swing.JOptionPane;
//消息对话框显示字符串
public class Q1 {
public static void main(String [] args){
JOptionPane.showMessageDialog(null, "Hello Java!");
//null是关键字,Hello Java!是要显示的字符串
JOptionPane.showMessageDialog(null, "Hello Java!", "Q1", JOptionPane.INFORMATION_MESSAGE);
//null是关键字,Hello Java是要显示的字符串,Q1是对话框标题,JOptionPane.INFORMATION_MESSAGE是要显示图标
System.out.println("Welecome to Java \n Welcome to Computer Science \n Programing is fun");
//system包含在Java.lang包里面
for(int i = 1; i<=5;i++){
System.out.println("Welcome to Java");
}
//显示welcome to Java 五次
System.out.println(" J\n J\nJ J\n JJ ");
//显示不规则图形
System.out.println((9.5*4.5-2.5*3)/(45.5-3.5));
//算数计算
int sum=0;
for(int j=1;j<10;j++){
sum= sum+j;
}
System.out.println(sum);
//数列求和
float result=0.0f;
for(float i =1,j=1;i<10000000;i=i+2,j++){
//i的值不能太大超出float的范围
float d;
if(j%2==0){
d = -1/i;
}
else{
d = 1/i;
}
result = result+d;
}
System.out.println(result*4);
}
//求π的近似值
}
//Java.lang包内的所有类都被默认导入在每一个Java程序中
import javax.swing.JOptionPane;
//消息对话框显示字符串
public class Q1 {
public static void main(String [] args){
JOptionPane.showMessageDialog(null, "Hello Java!");
//null是关键字,Hello Java!是要显示的字符串
JOptionPane.showMessageDialog(null, "Hello Java!", "Q1", JOptionPane.INFORMATION_MESSAGE);
//null是关键字,Hello Java是要显示的字符串,Q1是对话框标题,JOptionPane.INFORMATION_MESSAGE是要显示图标
System.out.println("Welecome to Java \n Welcome to Computer Science \n Programing is fun");
//system包含在Java.lang包里面
for(int i = 1; i<=5;i++){
System.out.println("Welcome to Java");
}
//显示welcome to Java 五次
System.out.println(" J\n J\nJ J\n JJ ");
//显示不规则图形
System.out.println((9.5*4.5-2.5*3)/(45.5-3.5));
//算数计算
int sum=0;
for(int j=1;j<10;j++){
sum= sum+j;
}
System.out.println(sum);
//数列求和
float result=0.0f;
for(float i =1,j=1;i<10000000;i=i+2,j++){
//i的值不能太大超出float的范围
float d;
if(j%2==0){
d = -1/i;
}
else{
d = 1/i;
}
result = result+d;
}
System.out.println(result*4);
}
//求π的近似值
}