Live2D

java练习---6

 1 //程序员:罗元昊  2017.9.24
 2 import java.util.Scanner;
 3 public class L {
 4 
 5     public static void main(String[] args) {
 6         long a ;                //练习题1:输出一个长整型的变量 123456789012345
 7         a=123456789012345l;
 8         System.out.println(a);
 9         
10         float b=2.4f;            //练习题2:输出一个单精度的小数常量 2.4
11         System.out.println(b);
12           
13         boolean c=true;            //练习题3:输出一个布尔类型的变量
14         System.out.println(c);
15         c=false;
16         System.out.println(c);    
17            
18         byte d=3;                //练习题4:强制类型转换
19         d=(byte)(d+200);
20         System.out.println(d);    
21              
22         System.out.println((char)('a'+1));//练习题5:输出1个字符型的加法计算
23         System.out.println((char)('你'+1));
24                 
25         int e=Integer.MAX_VALUE+1;        //练习题6:int 也对应着一个类,Integer 演示变量的溢出效果
26         System.out.println(e);
27                 
28         @SuppressWarnings("resource")      //练习题7:算术运算符+-*/
29         Scanner input=new Scanner(System.in);
30         double f;
31         System.out.println("Enter the x ");
32         f = Double.valueOf(input.nextDouble());
33         f=f/1000*1000;
34         System.out.println("The calculation result is " + f);
35         }
36 
37 }

 

 

  1 package cn.lyh;
  2 public class X{
  3     public static void main(String[] args){
  4         //第六题判断语句
  5         int weekDay=3;//判断星期
  6         if(weekDay==1){
  7             System.out.println("今天是星期一");
  8         }
  9         else if(weekDay==2){
 10             System.out.println("今天是星期二");
 11         }
 12         else if(weekDay==3){
 13             System.out.println("今天是星期三");
 14         }
 15         else if(weekDay==4){
 16             System.out.println("今天是星期四");
 17         }
 18         else if(weekDay==5){
 19             System.out.println("今天是星期五");
 20         }
 21         else if(weekDay==6){
 22             System.out.println("今天是星期六");
 23         }
 24         else if(weekDay==7){
 25             System.out.println("今天是星期日");
 26         }
 27         else{
 28             System.out.println("没有这一天");
 29         }
 30         int month=8;//判断季节
 31         if(month==3||month==4||month==5){
 32             System.out.println("现在是春天");
 33         }
 34         else if(month==6||month==7||month==8){
 35             System.out.println("现在是夏天");
 36         }
 37         else if(month==9||month==10||month==11){
 38             System.out.println("现在是秋天");
 39         }
 40         else if(month==12||month==1||month==2){
 41             System.out.println("现在是冬天");
 42         }
 43         else{
 44             System.out.println("没有这个季节");
 45         }
 46         //第七题使用分支语句
 47         int c=84,h=3;
 48             char option='+';
 49                switch (option)
 50             {
 51             case '+':
 52                     System.out.println("c+h="+(c+h));
 53                     break;
 54             case '-':
 55                     System.out.println("c-h="+(c-h));
 56                     break;
 57             case '*':
 58                     System.out.println("c*h="+(c*h));
 59                     break;
 60             case '/':
 61                     System.out.println("c/h="+(c/h));
 62                     break;
 63             case '%':
 64                     System.out.println("c%h="+(c%h));
 65                     break;
 66             default:
 67                     System.out.println("c%h="+(c%h));
 68                     break;
 69             }
 70         //使用switch判断季节
 71         int mon=8;
 72         switch(mon)
 73         {
 74         case 3:
 75         case 4:
 76         case 5:
 77             System.out.println("现在是春天");
 78             break;
 79         case 6:
 80         case 7:
 81         case 8:
 82             System.out.println("现在是夏天");
 83             break;
 84         case 9:
 85         case 10:
 86         case 11:
 87             System.out.println("现在是秋天");
 88             break;
 89         case 12:
 90         case 1:
 91         case 2:
 92             System.out.println("现在是冬天");
 93             break;
 94         default:
 95             System.out.println("没有这个季节");
 96             break;
 97         }
 98         //第八题do while和while的区别
 99         int d=1;
100         do{
101             System.out.println("d="+d);
102             d++;
103         }while(d<1);//不管while里面的条件是否成立,do里面的都要运行
104         int f=1;
105         while(f<1){
106             System.out.println("f="+f);
107             f++;
108         }
109         //第九题使用for语句写一个简单的循环语句
110         for(int g=1;g<5;g++)
111         {
112             System.out.println("g="+g);
113         }
114     }
115 }

 

posted @ 2017-09-24 19:24  Mr丶L  阅读(327)  评论(0编辑  收藏  举报