发布于2021-06-12 15:40 阅读(825) 评论(0) 点赞(11) 收藏(4)
文章目录:
3、报数游戏。A、B、C、D、E、F、G、H共8人站成一排,按图2.3所示的方法从1开始报数。编写一个Java程序,找出谁先报到19 431 0057?
4、用迭代法求正数n的平方根x,a由命令行参数给出。求平方根的迭代公式为xn+1=0.5×(xn+a/xn),要求前后两次求出的x的差的绝对值小于10-5。 x的迭代初始值为a/2
6、奇妙的算式。有人用字母代替十进制数字写出下面的算式。请编写一个Java程序,找出这些字母代表的数字
10、编写一Java程序,计算cosx=1-+- +…,精确到第n项,误差小于0.000 1,x的值由键盘输入
11、编写一个通用方法,在给出的一维数组中查找一个数,找到时输出已找到某数,未找到时输出未找到某数
12、定义一个4行4列的double型二维数组。创建一个方法显示数组并计算任意给定的行、给定的列、主对角线和副对角线的和以及数组中的最大值
- package com;
-
- import java.util.Scanner;
-
- public class day1
- {
-
-
- public static void main(String[] args)
- {
- char []天干 = {'甲','乙','丙','丁','戊','己','庚','辛','壬','癸'};
- char []地支 = {'子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥'};
- char []生肖 = {'鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'};
- int year;
- Scanner scanner = new Scanner(System.in);
- System.out.print("请输入年份:");
- year = scanner.nextInt();
- System.out.println("你输入的年份为:"+year);
- System.out.println("当年的天干地支为:"+天干[((year-3)%10)-1]+地支[((year-3)%12)-1]);
- System.out.println("当年所对应的生肖为:"+生肖[((year-3)%12)-1]);
- }
-
- }
编写程序,实现的功能是:将所有的一级汉字的区位码打印出来,并在区位码后面跟上其汉字本身。每打印8个汉字的相关信息后换行。
操作提示:使用for循环嵌套,外层循环从16~55,内层循环从l~94。注意在适当时使用break退出循环。定义一个拥有两个元素的byte类型数组,将区码加上十进制数160并赋给数组下标为0的元素;将位码加上十进制数160并赋给数组下标为1的元素。赋值时注意类型的强制转换。当byte数组的两个元素都取得值后,使用java.1ang.String类的“public String(byte[]bytes)”构造形式即可得到一个特定汉字。
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- int k=0;
- byte bytes[]=new byte[2];//定义一个拥有两个元素的byte类型数组
- String word="";
-
- for (int i=16;i<=55;i++)
- {
- for (int j=1;j<=94;j++)
- {
- //将区码加上十进制数160并赋给数组下标为0的元素
- bytes[0]=(byte)(i+160);
- //将位码加上十进制数160并赋给数组下标为1的元素
- bytes[1]=(byte)(j+160);
-
- word=new String(bytes);//赋值时注意类型的强制转换
- System.out.print(i+""+String.format("%02d",j));//当byte数组的两个元素都取得值后
- System.out.print(word);
-
- //5590、5591、5592、5593、5594这5个编码没有使用
- if (i==55 && j>=89)
- {
- break;
- }
-
- k++;
- if (k%10==0)
- {
- System.out.println();
- }
- }
- }
- }
-
- }
-
-
-
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- char []AH={'A','B','C','D','E','F','G','H'};
- Scanner scanner = new Scanner(System.in);
- System.out.print("请输入一个数:");
- int sc = scanner.nextInt();
- int a = sc/7;
- int b = sc%7;
- if (a%2==0){
- System.out.println("现报道的是:"+AH[b-1]);
- }else {
- System.out.println("现报道的是:"+AH[8-b]);
- }
- }
-
- }
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- double sum;
- Scanner scanner = new Scanner(System.in);
- System.out.print("请输入a的值:");
- double a = scanner.nextDouble();
- double x=a/2,h1=0,h2=0;
- do{
- h1=0.5*(x+a/x);
- x=h1;
- h2=0.5*(x+a/x);
- x=h2;
- sum=Math.abs(h1-h2);
- }while (sum>0.000001);
- System.out.println("h1:"+h1+" "+"h2:"+h2);
- System.out.println("差值k="+sum);
- }
-
- }
-
-
-
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- // A!=X C!=X C!Z 找出3对赛手的名单
- //C-Y A-Z B-X
- public class day1
- {
- public static void main(String[] args)
- {
-
- char i,j,k;
- for (i='x';i<='z';i++)
- {
- for (j='x';j<='z';j++)
- {
- if (i!=j)
- {
- for (k='x';k<='z';k++)
- {
- if (i!=k && j!=k)
- {
- if (i!='x' && k!='x' && k!='z')
- {
- System.out.println("A--"+i+"\n"+"B--"+j+"\n"+"C--"+k);
- }
- }
- }
- }
- }
- }
-
- /* char []ch1={'A','B','C'};
- char []ch2={'x','y','z'};
- *//*
- A与x[舍] A与z
- B与x B与y[舍] B与z[舍]
- C与y*//*
- for (int i=0;i<=2;i++){
- for (int j=0;j<=2;j++)
- {
- if ((i==0 && j==1) || (i==2&&j==0) || (i==2&&j==2))
- {
- }
- else
- {
- System.out.println(ch1[i]+"与"+ch2[j]);
- }
- }
- }*/
- }
-
- }
-
-
-
提示:每个字母代表值为0, 1, 2, 3, 4, 5, …, 9中的一个。使用四重穷举。
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- int []A={0,1,2,3,4,5,6,7,8,9};
- int []E={0,1,2,3,4,5,6,7,8,9};
- int []G={0,1,2,3,4,5,6,7,8,9};
- int []L={0,1,2,3,4,5,6,7,8,9};
- int count=0;
-
- for (int e=0;e<E.length;e++){
- for (int g=0;g<G.length;g++){
- for (int a=0;a<A.length;a++){
- for (int l=0;l<L.length;l++){
- int x1=E[e]*1000;
- int x2=G[g]*100;
- int x3=A[a]*10;
- int x4=L[l]*1;
- int sum=x1+x2+x3+x4;
-
- int y1=L[l]*1000;
- int y2=G[g]*100;
- int y3=A[a]*10;
- int y4=E[e]*1;
- int end=y1+y2+y3+y4;
- if (end==sum*L[l]){
- System.out.print(E[e]+""+G[g]+""+A[a]+""+L[l]+"\t");
- count++;
- if (count%17==0) System.out.println();
- }
- }
- }
- }
- }
- }
-
- }
-
-
-
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- int count=1;
- System.out.print("每一天的桃子数为:");
- for (int i=9;i>0;i--)
- {
- count=(count+1)*2;
- System.out.print(count+"个"+" ");
- }
- }
-
- }
- package com;
-
- import java.util.Scanner;
-
- public class day1 {
- static float p(int n,int x)
- {
- float sum;
- if (n == 0)
- {
- sum = 1;
- } else
- {
- if (n == 1)
- {
- sum = x;
- } else
- {
- sum = ((2 * n - 1) * x * p(n - 1, x) - (n - 1) * p(n - 2, x)) / n;
- }
- }
- return sum;
- }
-
- public static void main(String[] args) {
- float sum;
-
-
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入n:");
- int n = sc.nextInt();
- System.out.println("请输入x:");
- int x = sc.nextInt();
-
- sum = p(n,x);
-
- System.out.println("结果为:"+sum);
-
- }
-
- }
-
-
-
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- Scanner scanner = new Scanner(System.in);
- System.out.print("请输入月份:");
- int mth = scanner.nextInt();
- System.out.print("亲输入票数:");
- int count = scanner.nextInt();
- if (mth>=7 && mth<=9){
- if (count>=20){
- System.out.println(" "+"优惠票价10%");
- }else {
- System.out.println(" "+"优惠票价5%");
- }
- }else {
- if (count>=20){
- System.out.println(" "+"优惠票价20%");
- }else {
- System.out.println(" "+"优惠票价优惠10%");
- }
- }
- }
-
- }
-
-
-
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- System.out.print("请输入x的值:");
- Scanner scanner = new Scanner(System.in);
- double sc = scanner.nextDouble();
-
- double cosx=1;
- double m=1;
- do{
- for (int i=2;;i++)
- {
- m=(2*i)*(2*i-1);
- cosx+=-((sc*sc)/m);
- if (cosx<0.00001)
- {
- break;
- }
- }
-
- }while(cosx>0.00001);
- System.out.println("cosx="+cosx);
- }
-
- }
-
-
-
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- int []arr=new int[10];
- Scanner scanner = new Scanner(System.in);
- System.out.println("输入10个数!");
- for (int i=0;i<arr.length;i++){
- arr[i]=scanner.nextInt();
- }
- System.out.println("清输入要查找的数字:");
- int m = scanner.nextInt();
- for (int i=0;i<arr.length;i++){
- if (arr[i]==m){
- System.out.println("该数在数组中下标为"+i);
- }else System.out.println("err");
- }
- }
-
- }
- package com;
-
- import java.util.Scanner;
- import java.lang.String;
- public class day1
- {
- public static void main(String[] args)
- {
- int arr[][]=new int[4][4];
- Scanner scanner = new Scanner(System.in);
- System.out.println("请从键盘输入16个数:");
- for (int i=0;i< arr.length;i++){
- for (int j=0;j<arr[i].length;j++){
- arr[i][j]=scanner.nextInt();
- }
- }
-
- System.out.println("你输入的数组为:");
- for (int i=0;i<arr.length;i++){
- for (int j=0;j<arr[i].length;j++){
- System.out.print(arr[i][j]+"\t");
- }
- System.out.println();
- }
- System.out.println("请输入要计算的行号:");
- int rw = (scanner.nextInt()-1);
- int RWcount=0;
- for (int i=0;i<arr[rw].length;i++){
- RWcount+=arr[rw][i];
- }
- System.out.println(RWcount);
-
- System.out.println("请输入要计算的列号:");
- int cl = (scanner.nextInt()-1);
- int CLcount=0;
- for (int i=0;i<arr[cl].length;i++){
- CLcount+=arr[i][cl];
- }
- System.out.println(CLcount);
-
- System.out.println("主对角线和为:");
- int Ccount=0;
- Ccount=arr[0][0]+arr[1][1]+arr[2][2]+arr[3][3];
- System.out.println(Ccount);
-
- System.out.println("副对角线和为:");
- int Rount=0;
- Rount=arr[0][3]+arr[1][2]+arr[2][1]+arr[3][0];
- System.out.println(Rount);
- }
-
- }
-
-
-
原文链接:https://blog.csdn.net/liu17234050/article/details/117687581
作者:小胖子爱java
链接:http://www.javaheidong.com/blog/article/222502/03e91c09df477c9ef1e4/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!