dotcpp.com网站java编程题库-java程序流程控制(68题)

1.题目 1669: 求圆的面积

实现代码:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
			float a = scanner.nextFloat();
			System.out.printf("%.2f",Math.PI * a * a);
		}
	}
}

2.题目 1670: 拆分位数

实现代码:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
			int num = scanner.nextInt();
			int ge = num % 10;
			int shi = num /10 % 10;
			int bai = num / 100;
			System.out.printf("%d %d %d",ge,shi,bai);
		}
	}
}

3.题目 1761: 学习ASCII码

实现代码:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	    int a = (int)'t';
	    char b = (char)63;
		System.out.println(a+" "+b);
	}
}

4.题目 1762: printf基础练习

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	    int a = 123456789;
			System.out.printf("0%o 0x%x",a,a);
		
	}
}

5.题目 3000: 交换值

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			System.out.printf("%d %d",b,a);
		}
	}
}

6.题目 2760: 整型与布尔型的转换

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int a;
        boolean b;
        a = sc.nextInt();
        b = a != 0;
        a = b ? 1 : 0;
        System.out.println(a);
	}
}

7.题目2761:Hello, World!的大小

让用这个网站来学java 太刑了!!!
《算法》

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int a = 14;
		System.out.printf("%d",a);
	}
}

9.题目2765:计算分数的浮点数值

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            double a = scanner.nextDouble();
            double b = scanner.nextDouble();
            double c = a / b;
            System.out.printf("%.9f",c);
		}
	}
}

10.题目 1056: 二级C语言-温度转换

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
         // TODO Auto-generated method stub
         Scanner in=new Scanner(System.in);
         double f = in.nextDouble();   //输入一个双精度的值
         double C = (f-32)*5/9;  //代入公式
         System.out.printf("%.2f",C); //   %.2f为保留俩位小数
}
}

11.题目2752:整型数据类型存储空间大小

public class Main {
   public static void main(String[] args) {
       int a = 0;
       short b = 0;
       System.out.println(Integer.BYTES + " " + Short.BYTES);
   }
}

12.题目2752:浮点型数据类型存储空间大小

public class Main {
   public static void main(String[] args) {
       float a = 0;
        double b = 0;
        System.out.println(Float.BYTES + " " + Double.BYTES);
   }
}

13.题目2752:其他基本数据类型存储空间大小

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		char a = 0;
        boolean b = true;
        System.out.println("1 1");
	}
}

14.题目 2757: 浮点数向零舍入

import java.util.Scanner
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
double a = scanner.nextDouble();
System.out.printf("%d",(int)a);
}
}
}

15.题目 2758: 打印ASCII码

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String a;

a=sc.next();

System.out.println((int)a.charAt(0));

}

}

16.题目 2759: 打印字符

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a;

a=sc.nextInt();

System.out.println((char)a);

}

}


17.题目 3005: 糖果游戏

import java.util.Scanner;



public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int[] a=new int[5];

        for(int i=0;i<5;i++){

              a[i]=sc.nextInt();

        }

        for(int i=0;i<5;i++){

              int x=a[i]/3;

              a[i]=x;

              a[(i+1)%5]=a[(i+1)%5]+x;

              a[(i+4)%5]=a[(i+4)%5]+x;

        }

        for(int i=0;i<5;i++){

              System.out.printf("%5d",a[i]);

        }

    }

}

18.题目 2777: 计算2的幂

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
        int c =2;
        int a=sc.nextInt();
        int b=(int)Math.pow(c,a);
        System.out.println(b);
		
	}
}

19.题目 2780: 奇偶数判断

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			if(a%2==0){
			    System.out.println("even");
			}else {
			    System.out.println("odd");
			}
		}
	}
}

20.题目 2778: 判断数正负

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int N = scanner.nextInt();
			if (N>0) {
			    System.out.println("positive");
			}else if(N==0){
			    System.out.println("zero");
			}else if(N<0){
			    System.out.println("negative");
			}
		}
	}
}

21.题目 2783: 判断是否为两位数

import java.util.Scanner;
  
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int a = scanner.nextInt();
            if(a>9&&a<100){
                System.out.println(1);
            }else {
                System.out.println(0);
            }
              
        }
    }
}

22.题目 1043: [编程入门]三个数字的排序

import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int [] a=new int[3];
        for (int i=0;i<a.length;i++){
            a[i]=sc.nextInt();
        }
        //排序
        Arrays.sort(a);
        for (int t:a) {
            System.out.println(t);
        }
    }

}

23.题目 3006: 适合晨练

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int t = scanner.nextInt();
			if (25<=t&&t<=30) {
			    System.out.println("ok!");
			}else{
			    System.out.println("no!");
			}
			
		}
	}
}

24.收费

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			double a = scanner.nextDouble();
			if (a<=20) {
			    double b=1.68*a;
			    System.out.printf("%.2f", b);
			}else if (a>20) {
			    double c=1.98*a;
			    System.out.printf("%.2f", c);
			}
			
		}
	}
}

25.题目 1002: [编程入门]三个数最大值

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			a = a>b?a:b;
            a = a>c?a:c;
			System.out.println(a);
	}
}

26.奇偶ASCII值判断

import java.util.Scanner;
import java.text.DecimalFormat;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			double a = Math.abs(scanner.nextDouble());
            DecimalFormat df = new DecimalFormat("0.00");
            String c = df.format(a);
			System.out.println(c);
		}
	}
}

27.题目 2781: 奇偶ASCII值判断

import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
            char a = scanner.nextLine().charAt(0);
            if (a%2==0) {
                System.out.println("NO");
            }else  {
                System.out.println("YES");
            } 
    }
}

28.整数大小比较

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			if (x>y) {
			    System.out.println(">");
			}else if (x<y) {
		        System.out.println("<");
			}else  {
			    System.out.println("=");
		}
		
		}
	}
}

29.收集瓶盖赢大奖

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a>=10||b>=20) {
			    System.out.println(1);
			}else{
			    System.out.println(0);
			}
			
		}
	}
}

30.判断一个数能否同时被3和5整除

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			if (a%3==0&&a%5==0) {
			    System.out.println("YES");
			}else{
			    System.out.println("NO");
			}
		}
	}
}

31.判断能否被3、5、7整除

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			if (a%3==0) {
			    System.out.println(3);
			}if(a%5==0){
			    System.out.println(5);
			}if(a%7==0){
			    System.out.println(7);
			}if (a%3!=0&&a%5!=0&&a%7!=0) {
			    System.out.println("n");
			}
		}
	}
}

32.有一门课不及格的学生

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int yw = scanner.nextInt();
			int sx = scanner.nextInt();
			if (yw<60&&sx>=60) {
			    System.out.println(1);
			}else if (yw>=60&&sx<60) {
			    System.out.println(1);
			}else {
			    System.out.println(0);
			}
			
		}
	}
}

33.星期判断机

32、星期判断机
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			switch(a){
			  case 1:
			     System.out.println("Monday");
			     break;
			  case 2:
			     System.out.println("Tuesday");
			     break;
			  case 3:
			     System.out.println("Wednesday");
			     break;
			  case 4:
			     System.out.println("Thursday");
			     break;
			  case 5:
			     System.out.println("Friday");
			     break;
			  case 6:
			     System.out.println("Saturday");
			     break;
			  case 0:
			     System.out.println("Sunday");
			     break;
			  default:
			     System.out.println("input error!");
			         
			}
			
		}
	}
}

34.模拟计算器

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			String c= scanner.next();
			switch (c) {
			    case "+":
			        System.out.println(a+b);
			        break;
			    case "-":
			        System.out.println(a-b);
			        break;
			    case "*":
			        System.out.println(a*b);
			        break;
			    case "/":
			        System.out.println(a/b);
			        break;
			    case "%":
			        System.out.println(a%b);
			        break;
			    
			}
			
		}
	}
}

35.买笔

import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int x = s.nextInt();
        if(x%4==1)
        {
            System.out.println(0+" "+1+" "+(x/4-1));
        }
        else if(x%4==2)
        {
            System.out.println(1+" "+0+" "+(x/4-1));
        }
        else if(x%4==3)
        {
            System.out.println(1+" "+1+" "+(x/4-2));
        }
        else
        {
            System.out.println(0+" "+0+" "+x/4);
        }
    }
}

36.晶晶赴约会

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			switch(a){
			    case 1:
			        System.out.println("NO");
			        break;
			    case 2:
			        System.out.println("YES");
			        break;
			    case 3:
			        System.out.println("NO");
			        break;
			    case 4:
			        System.out.println("YES");
			        break;
			    case 5:
			        System.out.println("NO");
			        break;
			    case 6:
			        System.out.println("YES");
			        break;
			    case 7:
			        System.out.println("YES");
			        break;
			}
			
			
		}
	}
}

37.骑车与走路

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
double a=27+23+n/3.0;
double b=n/1.2;
if(a>b){System.out.println("Walk");}
else if(a==b){System.out.println("All");}
else{System.out.println("Bike");}
}
}

38.分段函数

**import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			double N = scanner.nextDouble();
			double y;
			if (N<5){
			    System.out.printf("%.3f", -N+2.5);
			} else if (N>=5&&N<10) {
			    System.out.printf("%.3f", 2-1.5*(N-3)*(N-3));
			}else if (N>=10&&N<20){
			    System.out.printf("%.3f",N/2-1.5);
			}
			
		}
	}
}**

39.计算邮资

import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       int kg = scanner.nextInt();
       char s = scanner.next().charAt(0);
       int sum=0 ;
       if (kg <= 1000) {
           sum=8;
       }else {
           sum=8+(kg-1000)/500*4;
               if ((kg-1000)%500!=0){
                   sum+=4;
                 
               }
       }
       if (s=='y'){
           sum+=5;
       }else {
        sum+=0;
       }
       System.out.println(sum);
       }
   }

40.三角形判断


41.判断闰年

import java.util.Scanner;
   
public class Main
{   public static void main(String[] args)
    {   Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        System.out.print((year % 400 == 0 || year % 4 == 0 && year % 100 != 0) ? "Y" : "N");
    }
}

42.点和正方形的关系

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			if (x<=1&&x>=-1 &&y<=1&&y>=-1){
			    System.out.println("yes");
			}else{
			    System.out.println("no");
			}
			
		}
	}
}

43.C语言考试练习题_一元二次方程

import java.util.Scanner;
   
public class Main
{   public static void main(String[] args)
    {   Scanner scanner = new Scanner(System.in);
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double c = scanner.nextDouble();
        double res1 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2;
        double res2 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2;
        System.out.printf("%.2f %.2f", res1, res2);
    }
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值