则继续按位相加:4+5=9 compassionate and stern "); break; case : System.out.println(str+ "("+i+")"+" is multi-talented decisive and a bit of a loner "); break; case : System.out.println(str+ "("+i+")"+" is money-oriented eccentric and domestic "); break; case : System.out.println(str+ "("+i+")"+" is spiritual careful and sensual "); break; case : System.out.println(str+ "("+i+")"+" is responsible mercurial and serious "); break; case : System.out.println(str+ "("+i+")"+" is adventurous traditional and fun-loving "); break; case : System.out.println(str+"("+i+")"+ " is practical optimistic and analytical "); break; case : System.out.println(str+ "("+i+")"+" is enthusiastic diplomatic and self-sufficient"); break; case : System.out.println(str+ "("+i+")"+" is supportive independent public class Generating Numbers from Names { public static String getEnter(String message){ String str=""; System.out.println(message+":"); BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); try { str=buf.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; } public static int getResult(char a) { int result = 0; int i=0; char ch='A'; i=Math.abs(ch-a)+1; if(i>18){ result=i-18; }else if(i>9){ result=i-9; }else{ result=i; } return result; } public static int getStringSumResult(String string){ int sum=0; string=string.toUpperCase(); for(int j=0;j<string.length();j++){ if('A'<=string.charAt(j)&&string.charAt(j)<'Z'){ sum+=getResult(string.charAt(j)); } } return sum; } public static int computeLastResult(int sum){ int lastresult=0; String str=sum+""; while(true){ int temp=0; for(int i=0;i<str.length();i++){ temp+=str.charAt(i)-48; } if(temp<=9){ lastresult=temp; break; }else{ str=temp+""; } } return lastresult; } public static void printResult(){ int i=0; String str=getEnter("please enter name"); i=computeLastResult(getStringSumResult(str)); switch(i){ case 后面是数字一直排下去: System.out.println(str+"("+i+")"+ " is ambitious 如果结果不是一个1-9之间的数字 如输入:Alan Turing1 2 3 4 5 6 7 8 9A B C D E F G H IJ K L M N O P Q RS T U V W X Y Z 则结果为1 + 3 + 1 + 5 + 2 + 3 + 9 + 9 + 5 + 7 = 45 然后根据这个对应关系把每个字母对应的数字累加起来 可以得出名字对应的人是一个什么样的人(有点占卜的味道 输入一个姓名 and global compassionate and stern 9 – is multi-talented decisive and a bit of a loner 8 – is money-oriented eccentric and domestic 7 – is spiritual careful and sensual 6 – is responsible mercurial and serious 5 – is adventurous traditional and fun-loving 4 – is practical optimistic and analytical 3 – is enthusiastic diplomatic and self-sufficient 2 – is supportive independent 根据最后的结果和下面的9种结果 其实逻辑很简单 呵呵)1 – is ambitious and global "); break; } } public static void main(String[] args) { printResult(); } } ||| 用javaSwing实现
java 难题
最新推荐文章于 2024-09-08 11:09:43 发布