/*程序员:张立平
需求1:输出 "5+5="+5+5
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{ System.out.println("5+5="+5+5);
}
}
/*程序员:张立平
需求2:输出 自增自减
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
int a=3,b;
b=a++;
System.out.println("a="+a+",b="+b);
}
}
/*程序员:张立平
需求3:输出
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
short c=3;
c=(short) (c+4); System.out.println("c="+c);
}
}
/*程序员:张立平
需求4:运算符与或
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
System.out.println(6&3); System.out.println(6|3); System.out.println(6^3); System.out.println(3<<2); System.out.println(3>>1);
}
}
/*程序员:张立平
需求5:运算符
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
int e=0,f; f=e>1?100:200; System.out.println("f="+f);
}
}
/*程序员:张立平
需求6: 用三元运算符做联系
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
@SuppressWarnings("resource") Scanner input=new Scanner(System.in); int x,y; System.out.println("Enter the x "); x=input.nextInt(); System.out.println("Enter the y "); y=input.nextInt(); y=x>y?x:y; System.out.println("The larger of the two numbers is"+y);
}
}
/*程序员:张立平
需求7:用if循环判断季节
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
@SuppressWarnings("resource") Scanner input11=new Scanner(System.in); int month; System.out.println("Enter the month "); month=input11.nextInt(); if(month>=3&&month<=5)
{ System.out.println("This month is spring"); } else if(month>=6&&month<=8)
{ System.out.println("This month is summer"); } else if(month>=9&&month<=11)
{ System.out.println("This month is autumn"); } else if(month==12)
{ System.out.println("This month is winter"); } else if(month>=1&&month<=2)
{ System.out.println("This month is winter"); } else
{ System.out.println("Error!"); }
}
}
/*程序员:张立平
需求8:使用switch判断季节
*/
import java.util.Scanner;
public class Z
{ public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int month;
System.out.println("Enter the month ");
month=input.nextInt();
switch (month)
{
case 1: case 2: case 12:
System.out.println("This month is winter");
break;
case 3: case 4: case 5:
System.out.println("This month is spring");
break;
case 6: case 7: case 8:
System.out.println("This month is summer");
break;
case 9: case 10: case 11:
System.out.println("This month is autumn");
break;
default:
System.out.println("Error!");
break;
}
}
}