求这6道Java题代码
3个回答
展开全部
①水仙花
for (int number=100;number<=999;number++ ){
int gewei=number%10;
int shiwei=number/10%10;
int baiwei=number/100%10;
if (gewei*gewei*gewei+shiwei*shiwei*shiwei+baiwei*baiwei*baiwei==number){
System.out.println("水仙花数是:"+number);
}
}
②判分
public String panfen(int fenshu){
String rs =null;
if(fenshu>=90 & fenshu<=100){
rs="A";
System.out.println("A");
}else if(fenshu<=89 & fenshu>75){
rs="B";
System.out.println("B");
}else if(fenshu<=74 & fenshu>60){
rs="C";
System.out.println("C");
}else if(fenshu<=59 & fenshu>0){
rs="D";
System.out.println("D");
}
return rs;
}
③计算字符个数
public Map<String,Integer> method(String a){
String str = a.replaceAll(" ", "");
char[] array = str.toCharArray();
Map<Character, Integer> map= new HashMap<Character, Integer>();
for (int i = 0; i < array.length; i++) {
if (array.length>1) {
if (map.get(array[i])==null) {
map.put(array[i], 1);
}else {
int value = map.get(array[i]).intValue();
value++;
map.put(array[i], value);
}
}
}
for(Map.Entry<Character, Integer> entry: map.entrySet()) {
System.out.print(entry.getKey() + "--" + entry.getValue() + "\n");
}
return null;
}
④小球
public void drop(int times) {
if ((times - 1) == 0) {
return;
}
setTotalHeight(getTotalHeight() + 2 * getCurHeight());
setCurHeight(getCurHeight() / 2);
drop(times - 1);
}
public double getTotalHeight() {
return TotalHeight;
}
public void setTotalHeight(double totalHeight) {
TotalHeight = totalHeight;
}
public double getCurHeight() {
return CurHeight;
}
public void setCurHeight(double curHeight) {
CurHeight = curHeight;
}
public static void main(String[] args) {
Test7 main = new Test7();
main.drop(10);
System.out.println("Total height is " + main.getTotalHeight());
System.out.println("Current height is " + main.getCurHeight());
}
⑤数字
int i=0; //保存百位上的数
int j=0; //保存十位上的数
int k=0; //保存各位上的数
int t=0; //保存数字个数
for(i=1;i<=4;i++){
for(j=1;j<=4;j++){
for(k=1;k<=4;k++){
if(i!=j && j!=k && i!=k){
t+=1;
System.out.println(i*100+j*10+k);
}
}
}
}
System.out.println (t);
⑥九九乘法表
for (int m = 1; m <= 9; m++) {
for (int n = 1; n <= m; n++) {
System.out.print(m + "x" + n + "=" + m * n + " ");
}
System.out.println();
}
展开全部
第1题:
public class BaiDu_1
{
public static void main(String[] args)
{
int sum;
for(int i=100;i<=999;i++)
{
sum=0;
for(int t=i;t!=0;t/=10)
sum+=Math.pow(t%10,3);
if(sum==i)
System.out.println(sum);
}
}
}
第2题:
import java.util.*;
public class BaiDu_2
{
public static void main(String[] args)
{
int score;
char grade;
Scanner read=new Scanner(System.in);
score=read.nextInt();
if(score>=90)
grade='A';
else if(score>=75)
grade='B';
else if(score>=60)
grade='C';
else
grade='D';
System.out.println(grade);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
想起个带,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询