public class Text{
public static void main(String[] args) {
int num = 456;
int bai = num / 100;
int shi = num / 10 % 10;
int ge = num % 10;
System.out.println("数字"+num+"的个位是"+ge+",十位是"+shi+",,百位是"+bai);
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(2)编写程序,生成5个1至10之间的随机整数,并打印结果到控制台。
*/
import java.util.Random;
public class Text{
public static void main(String[] args){
Random r = new Random();
for (int i = 0; i < 5;i ++){
int s = r.nextInt(10)+1;
System.out.println(s);
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(3)计算1-100之间的质数有多少个?将质数以及质数总数打印在控制台。
//质数:只能被1和本身整除的数.
public class Text_01{
public static void main (String[] args){
int count = 0;
aa:
for(int i = 2; i < 101; i++) {
for(int j = 2; j < i; j++) {
if(i%j == 0) {
continue aa;
}
}
count++;
System.out.println(i);
}
//(1)
import java.util.Scanner;
public class HomeWork3 {
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();
if(a<b) {
if(b<c) {
System.out.println("按照从小到大排序后的顺序为:"+a+" "+b+" "+c+"");
} else if(a < c) {//a < b c < b a<c
System.out.println("按照从小到大排序后的顺序为:"+a+" "+c+" "+b+"");
} else {//a < b c < b c< a
System.out.println("按照从小到大排序后的顺序为:"+c+" "+a+" "+b+"");
}
} else {//b<a
if(a<c) {//b<a a < c
System.out.println("按照从小到大排序后的顺序为:"+b+" "+a+" "+c+"");
} else if(b < c) {//b <a c < a b< c
System.out.println("按照从小到大排序后的顺序为:"+b+" "+c+" "+a+"");
} else {//b < a c < a c < b
System.out.println("按照从小到大排序后的顺序为:"+c+" "+b+" "+a+"");
}
}
}
}
/*(2)
public class Ha{
public static void main(String[] args){
int a,b,c;
int t;
counta> > b >> c;
if(a > b){
t = a; a = b; b = t;
}
if(a > c){
t = a ; a = c ; c = t;
}
if ( b >c){
t = b; b = c; c = t;
}
cout;
System.out.println()
public class Main {
public static void main(String[] args){
for(int i=1; i<10; i++){
for(int j=1; j<=i; j++){
System.out.print(j + "x" + i + "=" + (j*i));
System.out.print(" ");
}
System.out.println("");