1.3java语言基础(下)



1,Java数组的声明、赋值以及使用
2,使用数据解决求平均值、最大最小值问题
3,从控制台接收参数
4,向控制台输出数据

变量:保存数据(内存)独立的内存单元
数据类型:
1、原始数据类型
 int  32
 short 16
 long 64
 float 32
 double 64
 byte 8
 
 char 16
 boolean 1
 
2、引用数据类型:除开8种原始数据类型以外的所有数据类型

3、变量的命名规范:
 1、变量名只能由数字、字母、下划线、$组成
 2、不能由数字开头
 3、不能和关键字冲突
 4、见名起意
 5、中文可以作为变量名,但是不推荐使用
 
4、数据类型之间的转换:
 1、自动类型
 2、强制类型
 
表达式:运算符和操作数有效的组合
 x + y = 3
 (x+2)-(y-3)=11
 
运算符:
1、算术运算符
 二元:
  +:如果+号两边都是数字,计算功能;如果+号两边只要有一边是非数字,连接功能
  -:和数学中的用法一样
  *:和数学中的用法一样
  /:如果/号两边都是整数,取整;如果/两边只要有一边是非整数,除法功能
  %:取模(取余数)
 一元:
  ++:自增(1)
  --:自减(1)
  -:取反
2、关系运算符
3、逻辑运算符
 与:并且(&&:短路与 &逻辑与)
 &&:
 表达式1 && 表达式2:
 或:或者
 非:取反
4、条件运算符
5、赋值运算符 


定义一个四位数,求每个位数之和
int number = 1234;==>10
 
控制流语句:
1、判断语句
 if
 if...else
 if...else if...else if...else
 switch...case
 switch(常量){
 case 值1:代码1:;
 case 值2:代码2;
 default:代码;
 }
2、循环语句
3、跳转语句 
 
从控制台输入分数,采用等级制度输出等级:
大于90:A
大于80,小于90:B
70-80:C
60-70:D
小于60:E 
 
从控制台输入星期,如果输入的是1-5,打印工作日愉快,如果输入的是6或者是7
打印周末愉快 
 
 
 
 
 package com.newer.cn;

public class Demo1 {
 public static void main(String[] args) {
  int a = 10;
  int b = 11;
  
  System.out.println(a + b);//计算功能
  System.out.println(a + "newer");//连接功能10newer
  System.out.println(b - a);
  System.out.println(a * b);
  System.out.println( b / a);
  System.out.println(5.0 / 2);
  System.out.println(3 % 2);//1
  System.out.println(9.0 % 2);//1

 }

}

package com.newer.cn;

public class Demo2 {
 public static void main(String[] args) {
  int a = 6;
//  int b = ++a;
//  System.out.println(a);//7
//  System.out.println(b);//7
  
  int b = a++ + ++a + ++a + a++;
  System.out.println(a);//10
  System.out.println(b);//32
  
  //-
  System.out.println(-a);

 }

}
package com.newer.cn;

public class Demo3 {
 public static void main(String[] args) {
  int number = 9999;
  int ge = number % 10;
  int shi = number % 100 / 10;
  int bai = number / 100 % 10;
  int qian = number / 1000;
  System.out.println(ge + shi + bai + qian);

 }

}
package com.newer.cn;

public class Demo4 {
 public static void main(String[] args) {
  System.out.println(3==3);
  int a = 12;
  int b = 11;
  
  System.out.println(a != b);//true
  System.out.println(a > b);//true
  System.out.println(a < b);//false

 }

}
package com.newer.cn;

public class Demo5 {
 public static void main(String[] args) {
  int a = 5;//И│ох
  
  a+=6;//a = a + 6
  System.out.println(a);//11
  a-=6;//a = a - 6;
  System.out.println(a);//5
  
  a *= 2;//a = a * 2; 10
  System.out.println(a);
  a /= 2;//a = a / 2; 5
  System.out.println(a);
  a %= 2;//a = a % 2  1
  System.out.println(a);
 }

}
package com.newer.cn;

public class Demo6 {
 public static void main(String[] args) {
  int a = 22;
  int b = 33;
  
  int max = a > b ? a : b;
  System.out.println(max);
  
//  int max = 0;
//  if(a > b){
//   max = a;
//  }
//  if(a < b){
//   max = b;
//  }
//  System.out.println(max);

 }

}
package com.newer.cn;

import java.util.Scanner;
public class Demo7 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  System.out.println("请输入成绩:");
  //接受从控制台输入的数据
  double score = sc.nextDouble();
  if(score > 80){
   //条件成立执行
   System.out.println("成绩优秀!");
  }
  System.out.println("test.....");
  
 }

}
package com.newer.cn;
import java.util.Scanner;
public class Demo8 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  System.out.println("请输入令狐冲的java成绩:");
  double javaScore = sc.nextDouble();
  if(javaScore > 90){
   System.out.println("送独孤九剑剑谱");
  }else{
   System.out.println("闭门思过!!");
  }
  

 }

}
package com.newer.cn;

import java.util.Scanner;

public class Demo9 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
//  int a = 1;
  System.out.println("请输入星期:");
  int weekDay = sc.nextInt();//4
  switch (weekDay) {
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
   System.out.println("工作日快乐!");
   break;
  case 6:
  case 7:
   System.out.println("周末愉快!");
   break;
//  default:
//   System.out.println("输入错误!");
  }

  // if(weekDay >= 1 && weekDay <= 5){
  // System.out.println("工作日愉快");
  // }else if(weekDay == 6 || weekDay == 7){
  // System.out.println("周末愉快");
  // }else{
  // System.out.println("输入错误!");
  // }
 }

}
package com.newer.cn;

import java.util.Scanner;

public class Dem09 {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  System.out.println("请输入分数:");
  double score = sc.nextDouble();//75
  if(score >= 90){
   System.out.println("A");
  }else if(score >= 80 && score < 90){
   System.out.println("B");
  }else if(score >= 70 && score < 80){
   System.out.println("C");
  }else if(score >= 60 && score< 70 ){
   System.out.println("D");
  }else{
   System.out.println("E");
  }

 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值