输出九九乘法表
package com.Kuang.struct;
public class Example03 {
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+"="+(j*i)+"\t");
}
System.out.println();
}
}
}
输出直角三角形
package com.Kuang.struct;
import java.util.Scanner;
public class Example05 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("你想打印的三角形行数为:");
int n = in.nextInt();
for(int i = 1; i <= n; i++) {
for(int j = 1; j<=i; j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
输出等腰三角形
package com.Kuang.struct;
import java.util.Scanner;
public class Example06 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入打印行数:");
int n = scanner.nextInt();
for (int i =1; i <=n; i++){
for (int j =1; j<=n-i; j++){
System.out.print(" ");
}
for (int k=1; k<=2*i-1;k++){
System.out.print("*");
}
System.out.print("\n");
}
}
}
简单计算器
package com.Kuang.method;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入数字:");
double num1 = scanner.nextDouble();
System.out.print("请输入符号:");
String operator = scanner.next();
System.out.print("请输入数字:");
double num2 = scanner.nextDouble();
double result = 0;
switch (operator){
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
case "/":
result = num1 / num2;
break;
case "%":
result = num1 % num2;
break;
default:
System.out.println("输入不合法!");
}
System.out.println("计算结果为:"+num1 +operator+ num2 +"="+result);
scanner.close();
}
}