小例子
package com.tedu.study._day01;
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) {
System.out.println("请输入第一个整数:");
int a1=new Scanner(System.in).nextInt();
System.out.println("请输入第二个整数:");
int a2=new Scanner(System.in).nextInt();
System.out.println("请输入第三个整数:");
int a3=new Scanner(System.in).nextInt();
int max=a1;
if((max>a2)&&(max>a3)){
max=max;
}else{
if(a2>a3){
max=a2;
}else{
max=a3;
}
}
System.out.println("最大值:"+max);
}
}
package com.tedu.study._day01;
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) {
System.out.println("请输入一个月份值,判断当前月所属季节:");
try{
int a1=new Scanner(System.in).nextInt();
if(a1>=1&&a1<=12){
}else if(a1==3||a1==4||a1==5){
System.out.println("春季");
}else if(a1==6||a1==7||a1==8){
System.out.println("夏季");
}else if(a1==9||a1==10||a1==11){
System.out.println("秋季");
}else if(a1==12||a1==1||a1==2){
System.out.println("冬季");
}
}catch(InputMismatchException e){
System.out.println("输入类型有误!");
}
}
}
int a = 0, b = 0, c = 0, sum = 0;
while (a <= 100) {
sum += a;
a++;
}
System.out.println("从1加到100的和:" + sum);
while (b <= 300) {
if (b % 7 == 0) {
System.out.print(b + "\t");
}
b++;
}
System.out.println("请输入一位数字:");
int s = new Scanner(System.in).nextInt();
int i=1;
s=s/10;
while(s!=0){
i++;
s=s/10;
}
System.out.println("长度为"+i);
int aa = 128;
int bb = 1;
String result = "";
while (0 != aa) {
bb = aa % 2;
aa = aa / 2;
result = bb + result;
}
System.out.println(result);
*
**
***
****
****
***
**
*
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 4; i > 0; i--) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(i + "*" + j + "=" + (i * j) + "\t");
}
System.out.println();
}
package com.tedu.study._day01;
public class Demo01 {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int j = i; j <= 9; j++) {
System.out.print(Con(i) + Con(j) + (i * j >= 10 ? "" : "得")
+ Con(i * j));
System.out.print((i * j > 10) ? " " : " ");
}
System.out.println();
}
}
public static String Con(int di) {
String dig[] = { "十", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
if (di < 10) {
return dig[di];
} else if (di == 10) {
return dig[di / 10] + dig[0];
} else {
return dig[di / 10] + dig[0] + dig[di % 10];
}
}
}
*
**
***
****
****
***
**
*
for (int i = 1; i <= 4; i++) {
for (int j = 4; j >= 1; j--) {
if (j - i <= 0) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
if (j - i >= 0) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}