*/
import java.util.Scanner;//导包
class Case
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);//调用对象
System.out.println("请输入选项:");//提示
int number = sc.nextInt();//获取键盘录入的下一个int值
//选择结构
switch (number)
{
case 1:
case1();
break;
case 2:
case2();
break;
case 3:
xingXing();
break;
case 4:
cheng99();
break;
default:
System.out.println("输入有误");
break;
}
}
//1.让用户在控制台输入两个整数,然后交换顺序输出. -- 这将两种方式都敲一下
public static void case1()
{
System.out.println("请输入第一个数:");//提示
Scanner sc = new Scanner(System.in);//调用数据
int number1 = sc.nextInt();//获取键盘录入的int值
System.out.println("请输入第二个数");
//Scanner sc = new Scanner(System.in);
int number2 = sc.nextInt();
System.out.println("请输入第一个数:");
Scanner sc = new Scanner(System.in);//调用数据
int number1 = sc.nextInt();//获取键盘录入的下一个int值
System.out.println("请输入第二个数");
int number2 = sc.nextInt();
//获取两个数之间所有偶数的和.
if (number1 <number2)
{
int sum = 0;
int x = number1;
while (x<number2)
{
if (x % 2 == 0)
{
sum+=x;
}
x++;
}
System.out.println("两个数之间的偶数和为:"+sum);
}else
{
int sum = 0;
int x = number2;
while (x<number1)
{
if (x % 2 == 0)
{
sum+=x;
}
x++;
}
System.out.println("两个数之间的偶数和为:"+sum);
}
}
//3:打印*
public static void xingXing()
{
System.out.println("请输入行数:");
Scanner sc = new Scanner(System.in);
int hang = sc.nextInt();
//画三角形* 正三角形,改变内循环的判断条件
for (int x = 0;x<hang ;x++ )
{
for (int y=0;y<=x ;y++ )
{
System.out.print("*");
}
System.out.println();
}
}
//4:99乘法表
public static void cheng99()
{
System.out.println("surpise:");
for (int x = 1;x <=9 ;x++ )
{
for (int y =1;y<=x ;y++ )
{
System.out.print(y+"*"+x+"="+x*y+"\t");
}
System.out.println();
}