package cn.com.training.student;
import java.util.Scanner;
public class Training12 {
public static void main(String[] agrs){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个大于一百的三位数:");
int i = sc.nextInt();
int sum = 0;
//使用for循环获取100到该数字之间的所有数字
for(int j = 101;j if(i/100!=3 && (i/10)%10!=5 && i%10!=7){
System.out.println(j);
sum +=j;
}
}
System.out.println("该数的百位数是:"+i/100);
System.out.println("该数的十位数是:"+(i/10)%10);
System.out.println("该数的个位数是:"+i%10);
System.out.println("符合条件的数字的总和为:"+sum);
sc.close();
}
}
package cn.com.training.student;
import java.util.Scanner;
public class Training13 {
public static void main(String[] agrs){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入数字:");
int num = scanner.nextInt();
while(true){
switch(num){
case 1:
System.out.println("新建");
break;
case 2:
System.out.println("打开文件");
break;
case 3:
System.out.println("保存");
break;
case 4:
System.out.println("刷新");
break;
case 5:
System.out.println("退出");
System.exit(0);
break;
default:
System.out.println("请重新输入!");
}
}
//scanner.close();
}
}
package cn.com.training.student;
import java.util.Random;
import java.util.Scanner;
public class Training14 {
public static void main(String[] agrs){
Scanner sc = new Scanner(System.in);
System.out.println("猜数字");
System.out.println("请随机输入1-100之间的数字");
int i = sc.nextInt();
Random ra = new Random();
int j = ra.nextInt(100);
System.out.println(j);
while(i>-100){
if(i>j){
System.out.println("猜大了!请重新猜!");
}else if(i
}else if(i==j){
System.out.println("恭喜猜对了!");
break;
}
System.out.println("请重新输入:");
i = sc.nextInt();
}
sc.close();
}
}
package cn.com.training.student;
public class Training15 {
public static void main(String[] agrs){
double paper = 0.0001;
int count = 0;
while(true){
if(paper<8848){
paper = paper *2;
count++;
}else {
break;
}
}
System.out.println("折叠"+count+"次"+",可以折成珠穆朗玛峰的高度");
}
}
package cn.com.training.student;
import java.util.Scanner;
public class Training16 {
public static void main(String[] agrs){
Scanner sc = new Scanner(System.in);
System.out.println("请输入五个数字");
int[] nums = {0,0,0,0,0};
nums[0] = sc.nextInt();
for(int i=0;i
}
int min = getMin(nums);
System.out.println("min="+min);
sc.close();
}
static int getMin(int[] nums){
int min = nums[0];
for(int i=0;i
}
}
return min;
}
}
package cn.com.training.student;
import java.util.Random;
public class Training17 {
public static void main(String[] agrs){
//导入随机数包,生成随机数
Random ra = new Random();
//定义一个20元素的数组
int[] arr = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
arr[0] = ra.nextInt(100);
//使用for循环遍历数组
for (int i=0;i
arr[i] = ra.nextInt(100);
}
printArray(arr);
}
//重新定义一个打印数组的方法
public static void printArray(int[] arr){
//利用for循环遍历数组
for(int i=0;i
if(i==0){
System.out.print("[");
}
if(i==arr.length-1){
System.out.print(arr[i]+"]");
}else{
System.out.print(arr[i]+",");
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)