java语言程序设计第五章5.32+后部分习题答案

5.33

java语言程序设计第五章5.32+后部分习题答案_第1张图片[题目哈之后就不标注了]
//
import java.util.Scanner;public class text {public static void main(String[] args) {
int i;
System.out.println(“the perfect number are”);
for(i=1;i<10000;i++) {
int sum=0;
for(int j=1;j

if(i%j0) {
sum=sum+j;
}
}
if(sum
i) {
System.out.print(i+" ");
}
}}}

5.37
在这里插入图片描述
//
import java.util.Scanner;public class text {public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.print(“input an integer”);
int num=input.nextInt();
String a="";
while(num!=0) {
a=num%2+a;
num=num/2;
}
System.out.print(a);}}

java语言程序设计第五章5.32+后部分习题答案_第2张图片
//
import java.util.Scanner;public class text {public static void main(String[] args) {
int count=0;
int n1=1;
int n2;
while(n1<8) {
n2=n1+1;
while(n2<8) {
System.out.println(n1+" "+n2);
n2++;
count++;
}
n1++; }
System.out.println(“The total number of all combination is”+count);}}
5.49
java语言程序设计第五章5.32+后部分习题答案_第3张图片
/ /
import java.util.Scanner;public class text {public static void main(String[] args) {
Scanner input =new Scanner(System.in);
String a=input.nextLine();
int n;
int count=0;
int count1=0;
for(n=0;n char b=a.charAt(n);
if (b==‘A’||b==‘a’){
count++;
}
else if (b==‘I’||b==‘i’){
count++;
}
else if (b==‘E’||b==‘e’){
count++; }
else if (b==‘O’||b==‘o’){
count++; }
else if (b==‘U’||b==‘u’){
count++; }
else if(b==’ ')
count1++; }
count1=a.length()-count-count1;
System.out.println("The number of vowels is "+count);
System.out.println("The number of consonants is "+count1);}}
5.51java语言程序设计第五章5.32+后部分习题答案_第4张图片
//
import java.util.Scanner;public class text {public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.printf("Enter the first string: ");
String a=input.nextLine();
System.out.printf(“Enter the second string: “);
String b=input.nextLine();
int i=0;
for(i=0;i if(a.charAt(i)!=b.charAt(i))
break; }
if(i==0)System.out.println(a+” and “+b+” have no common prefix”);

else System.out.println("The common prefix is "+a.substring(0,i)); }}
这题是同学写的,嘤嘤嘤写得比我简单。

————————
新人刚接触Java
第一次写博客哈
想留下点纪念
看看自己Java到底能学到那一步。
(哈哈哈还不会用那个网站上的编译界面,各位看官将就看吧,小弟还在学习)

你可能感兴趣的:(新人)