这几天感觉比较有意思的代码
三个数大小排序
import java.util.Scanner;
public class PaiXu {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入第一个整数");
int a=sc.nextInt();
System.out.println("请输入第二个整数");
int b=sc.nextInt();
System.out.println("请输入第三个整数");
int c=sc.nextInt();
luRu(a,b,c);
}
public static void luRu(int a ,int b,int c){
int max=0;
int min=0;
if(a>b && a>c){
max=a;
}else if(b>a && b>c){
max=b;
}else if(c>a && c>b){
max=c;
}else if(b < a && b < c){
min=b;
}else if(b>a&&c>a){
min=a;
}else if(b>c&&a>c){
min=c;
}else{
System.out.println("有误");
}
int zhong=a+b+c-max-min;
System.out.println("从大到小的顺序是:"+max+" "+zhong+" "+min);
}
}
将键盘输入的数插入到新数组中
import java.util.Scanner;
public class ChaRu {
public static void main(String[] args) {
int [] arr = {12,25,36,45,48,52,65,69,72,78,85};
int [] brr=new int[11];
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个数字");
int num=sc.nextInt();
int count=0;
for(int i=0;i<arr.length;i++){
if(num<=arr[i]){
brr[i]=arr[i];
count=i+1;
}else{
brr[i+1]=arr[i];
}
}
brr[count]=num;
System.out.println("生成的新数组是:");
for(int i=1;i<brr.length;i++){
System.out.println(brr[i]+"");
}
}
}
输出乘法口诀表
import java.util.Scanner;
public class ChengFaBiao {
public static void main(String[] args) {
DaYin();
}
public static void DaYin(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个1-9之间的整数");
int a=sc.nextInt();
for(int i=1;i<=a;i++){
for (int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+(j*i)+" ");
}
System.out.println();
}
}
}
找出100以内带7和7倍数的数字
public class GetSeven {
public static void main(String[] args) {
getSevenPass(100);
}
public static void getSevenPass(int num){
int count=0;
for(int i=1;i<=num;i++){
if(i%7==0||i/10%10==7||i%10==7) {
count++;
if (count%5==0){
System.out.println(i);
}else{
System.out.print(i+" ,");
}
}
}
}
}
|
|