数据基本类型以及相关举例

摘要:
数据基本类型:整数:字节短整数int浮点类型:长浮点类型fioat双精度字符类型:char布尔类型:布尔引用类型(引用):类接口数据数组循环:forwhiledowhilesewitch(case默认)packagehuigu 20161128;publicclassArrayTest1{p

数据基本类型:

整型:字节型byte 短整型short  整型int 
浮点类型:长整形long  浮点型  fioat   双精度性double 
字符型:char 
布尔型:boolean
 
引用类型( reference):
类class   接口interface   数据  array
 
 
循环:for   while      do while     switch (case   default   )
package huigu20161128;
 
public class ArrayTest1 {
 
    public static void main(String []args){
        int sum=0;
        int arr[]={11,22,33,44,55};
        for(int i=0;i<arr.length;i++){
            sum=sum+arr[i];
        }
        System.out.println("arr总和为"+sum);       
       String[] arr1=new String[5]; //必须指定大小
        for(int i=0;i<arr1.length;i++){
            System.out.println(arr1[i]);
       } 
        int [][] arr={
                {1,2,3,45},
                {1,3,4},
                {6,53,3}
        };
       
        int sum=0;
       for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr[i].length;j++){
            sum=sum+arr[i][j];        
            }
      }       
 System.out.println("sum="+sum);
          String s="";//定义一个空字符串
       String [][] str=new String [2][];
       String st[]={"strty","tr1","str2"};
       String st1[]={"sr","sb","cc"};
        str[0]=st;
        str[1]=st1;
        for(int i=0;i<str.length;i++){
            for(int j=0;j<str[i].length;j++){
            if(str[i][j].contains("s") && str[i][j].length()<3){}
               s=s+str[i][j];
            }
        }
        System.out.println("s="+s);
    }
}
package huigu20161128;
 
public class Ifdemo2 {
    //数据基本类型:整型: byte short int  long
    //字符:char    布尔类型  boolean:true false  浮点型:double float
     
    //引用类型:String  
    
//    int c;//成员变量 初始值 :0
//    String str;//初始值  null
//  
    public static void main(String []args){
//        int a=11;//局部变量
//        int b=9;
//        //if 单分支
//        if(a>b){
//            System.out.println("a>b");
//        }    
        
        
        //if 双分支
//        if(a>b){
//         System.out.println("a>b");
//       }else{
//           System.out.println("a<=b");
//       }
        
        //if 多分支
//        int score=70;//分数
//        if(score<=100 && score>=90){
//            System.out.println("优秀");
//        }else if(score>80 && score<90){
//            System.out.println("良好");
//        }else if(score<=80 && score>=60){
//            System.out.println("及格");
//        }else{
//            System.out.println("不及格");
//        }
        
        
        
        //for 循环
//        for(int i=0;i<100;i++){
//            //1.定义一个变量 i=0  2.判断i  3.运行程序体  4.i++  5.判断
//            System.out.println(i);
//        }
        
//        for(int i=0;i<10;i++){//双层for循环 外层控制行  内层控制列
//            for(int j=0;j<10;j++){
//            System.out.print("*");    
//          }
//            System.out.println();
//        }
        
        //while循环
//        int a=1;
//        while(a<10){
//            System.out.println("还满足循环体");
//            //a--;//a=a-1;
//            a++;//a=a+1;
//            if(a==6){
//              break;
//            }
//        }
        
//        int a=9;
//        //do while
//        do{
//            System.out.println("至少执行一次");
//       }while(a>10);
        
        
        //switch case
        int a=4;
        switch (a) {
        case 1:
            System.out.println("1");
            break;
        case 2:
            System.out.println("2");
            break;
        case 3:
            System.out.println("3");
            break;
 
        default:
            System.out.println("一个条件不满足");
            break;
        }
        
    }
    
}
 
package huigu20161128;
 
public class MethodTest3 {
    
    public void TestMax(){
        System.out.println("我是一个方法");
    }
    
    public boolean TestM(int a,int b){
        if(a>=b){
            return true;
        }else{
            return false;
        }
        
        
}
    
  public static void main(String []args){
      MethodTest3 mt=new MethodTest3();
//      mt.TestMax();
      
      int a=10;
      int b=13;
   if(mt.TestM(a, b)){
      System.out.println("a>=b"); 
   }else{
       System.out.println("a<b");
   }
      
      
      
  }
    
    
    
}
package huigu20161128;
 
import java.util.Scanner;
 
public class SumScore5 {
//    int a=10;
//    int b=11;
//    System.out.println(a+b+"a="+(a+b));
    
    
    public static void main(String []args){
    Scanner scan=new Scanner(System.in);
    int score;//定义变量
    double sum = 0;
    for(int i=0;i<5;i++){
          System.out.println("请输入一个整数的分数:");
        score=scan.nextInt();//接受键盘输入
        sum=sum+score;
      }
    System.out.println("你的总分数是"+sum);    
    System.out.println("你的平均分是"+(sum/5));      
}
 
}

免责声明:文章转载自《数据基本类型以及相关举例》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Cocos2dx-lua开发之c++绑定到luaminihttp http://www.acme.com/software/mini_httpd/下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Java 权限框架 Shiro 实战一:理论基础

Apache Shiro 官网地址:http://shiro.apache.org/ Apache Shiro is a powerful and easy-to-use Java security framework that performs authentication, authorization, cryptography, and sessio...

死磕 java集合之WeakHashMap源码分析

欢迎关注我的公众号“彤哥读源码”,查看更多源码系列文章, 与彤哥一起畅游源码的海洋。 简介 WeakHashMap是一种弱引用map,内部的key会存储为弱引用,当jvm gc的时候,如果这些key没有强引用存在的话,会被gc回收掉,下一次当我们操作map的时候会把对应的Entry整个删除掉,基于这种特性,WeakHashMap特别适用于缓存处理。 继承体...

【216】◀▶ IDL 字符串操作说明 (黑底)

参考:String Processing Routines —— 字符串处理函数 参考:IDL_String Methods 01   STRING 返回字符串。 02   STRCMP 比较字符串,一样返回1,不一样返回0,默认大小写敏感。 03   STRMATCH 字符串进行比较,一致返回1,不一致返回0。 04   STRCOMP...

wchar_t,char,string,wstring等的总结

一、LPSTR LPCSTR LPTSTR LPCTSTR等 确定的类型: LPSTR = CHAR * = char *LPCSTR = const CHAR * = char * //c意为const  不确定类型(可变型): LPTSTR = LPWSTR = WCHAR * = wchar_t * //(Unicode编码) = LPSTR =...

C#综合揭秘——细说多线程(上)

引言   本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个方面介绍多线程的开发。   其中委托的BeginInvoke方法以及回调函数最为常用。   而 I/O线程可能容易遭到大家的忽略,其实在开发多线程系统,更应该多留意I/O线程的操作。特别是在ASP.NET开发当中,可能更多人只会留意在客户端使用Ajax...

Java基础知识提要

1、简述Java的基本历史 java起源于SUN公司的一个GREEN的项目,其原先目的是:为家用消费电子产品发送一个信息的分布式代码系统,通过发送信息控制电视机、冰箱等 2、简单写出Java特点,写出5个以上,越多越好 简单的、面向对象的、分布式的、安全的、稳定的、与平台无关的、可解释的、多线的、动态的语言。 3、什么是Java? JAVA:一种编程...