Java基础2

来源:互联网 发布:小米max usb网络共享 编辑:程序博客网 时间:2024/06/11 01:21

第一天:Java概述和基本语法

  1. Java的术语

    • JDK:Java Developer’s Kit - Java开发者工具
    • JRE:Java Runtime Environment - Java运行时环境
    • JVM:Java Virtual Machine - Java虚拟机
    • API:Application Programming Interface - 应用程序编程接口
  2. 开发工具和开发环境

    • Eclipse
    • IntelliJ

练习1:输出下面的图案

*******************               **  欢迎来到狼窝 **               *******************
package com.lovoinfo;public class Hello {    public static void main(String[] args) {        System.out.println("*************************");        System.out.println("*\t\t\t*");        System.out.println("*\t欢迎来到狼窝\t*");        System.out.println("*\t\t\t*");        System.out.println("*************************");    }}

练习2:在弹出式对话框上输出上面的图案

package com.lovoinfo;import javax.swing.JOptionPane;public class WangQian2 {    public static void main(String[] args){        String name=JOptionPane.showInputDialog("请输入您的尊姓大名:");        String message="*****************" +                "****\n*欢迎"+name+"来到狼窝*\n*********************";        JOptionPane.showMessageDialog(null, message);    }}

联系3:计算器的代码

package com.lovoinfo;import javax.swing.JOptionPane;public class calculator2 {    public static void main(String[] args) {         String m = JOptionPane.showInputDialog("请输入第一个数字:");         String n =  JOptionPane.showInputDialog("请输入第一个数字:");         int a = Integer.parseInt(m);         int b = Integer.parseInt(n);         String message = String.format("%d+%d=%d\n",a,b,a+b);          String message2 = String.format("%d-%d=%d\n",a,b,a-b);         String message3 = String.format("%d*%d=%d\n",a,b,a*b);         String message4 = String.format("%d/%d=%d\n",a,b,a/b);         JOptionPane.showMessageDialog(null,                  message+message2+message3+message4);    }}

练习4:判断一个人的身高体重是否正常

package com.lovoinfo;import java.util.Scanner;public class TZ {    public static void main(String[] args) {        Scanner a =new Scanner(System.in);        System.out.println("请输入您的体重:");        int b = a.nextInt();        System.out.println("请输入您的身高:");        int c=a.nextInt();    if (c-110>=b){        System.out.print("您的体重正常");    }    else{        System.out.print("您体重有点傻逼");    }    a.close();    }}

作业:把摄氏温度转换为华氏温度

package com.lovoinfo;import javax.swing.JOptionPane;public class calculator3 {    public static void main(String[] args) {        String a = JOptionPane.showInputDialog( "请输入摄氏温度:");        double m= Double.parseDouble(a);        JOptionPane.showMessageDialog(null, m+"摄氏度等于"+(1.8*m+32)+"华氏度");    }}

找出三个数中的最大值

package com.lovoinfo;import java.util.Scanner;public class WQ {    public static void main(String[] args) {        Scanner m = new Scanner(System.in);        System.out.println("请输入三个整数:");        int a = m.nextInt();        int b = m.nextInt();        int c = m.nextInt();        if (a>=b && a>=c){            System.out.println(a);                  }        else if(b>=c){            System.out.println(b);          }        else{            System.out.println(c);        }               m.close();          }}

变量的命名:

1.字母、数字、下划线、和$,但数字不能作开头,字母包括汉子和其他国家的语言。
2.大小写敏感
3.不能与关键字冲突
4.见名知意首字母大写(不作硬性要求,但强烈建议)
5.特殊字符不可以

0 0
原创粉丝点击