import java.util.Scanner;
class IfTest
{
public static void main(String[] args)
{
System.out.println("请输入一个数值:例如:2!");
Scanner s=new Scanner(System.in);
int week = s.nextInt();
if(week == 1)
System.out.println(week+"对应的是星期一");
else if(week == 2)
System.out.println(week+"对应的是星期二");
else if(week == 3)
System.out.println(week+"对应的是星期三");
else if(week == 4)
System.out.println(week+"对应的是星期四");
else if(week == 5)
System.out.println(week+"对应的是星期五");
else if(week == 6)
System.out.println(week+"对应的是星期六");
else if(week == 7)
System.out.println(week+"对应的是星期日");
else
System.out.println(week+"没有对应的星期");
}
}
import java.util.Scanner;
class SwitchTest
{
public static void main(String[] args)
{
System.out.println("请输入一个数值:例如:2!");
Scanner s=new Scanner(System.in);
int week = s.nextInt();
switch(week)
{
case 1:
System.out.println(week+"对应的是星期一");
break;
case 2:
System.out.println(week+"对应的是星期二");
break;
case 3:
System.out.println(week+"对应的是星期三");
break;
case 4:
System.out.println(week+"对应的是星期四");
break;
case 5:
System.out.println(week+"对应的是星期五");
break;
case 6:
System.out.println(week+"对应的是星期六");
break;
case 7:
System.out.println(week+"对应的是星期日");
break;
default:
System.out.println(week+"没有对应的星期");
break;
}
}
}
//1,定义变量。一个记录和,一个记录下一个数。
int i = 1;
int sum = 0;
//2,需要循环结构。
while(i<=10)
{
//3,循环中需要进行和+下一个数的运算。并让下一个数自增。
sum = sum + i;
i++;
}
System.out.println("sum="+sum);
class ForTest
{
public static void main(String[] args)
{
//1,定义变量,记录个数。
int count = 0;
for (int x = 1; x<=100 ; x++ )
{
//对数值进行判断,是否是6的倍数。
if(x % 6 == 0)
count++;
}
System.out.println("count="+count);
}
}
public class Text03 {
public static void main(String[] args) {
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
}
/**
* 上半部分 等腰三角 空心
* 下半部分 倒等腰三角 空心
*/
for (int i =6 ;i>=1;i--){
for (int j = 1;j<=11;j++){
if(i==j||j==12-i){
System.out.print("*");
}else {
System.out.print(" ");
}
}
System.out.println();
}
for (int i = 2;i<=6;i++){
for (int j = 1;j<=11;j++){
if(i==j||j==12-i){
System.out.print("*");
}else {
System.out.print(" ");
}
}
System.out.println();
}