1、java答案import java.util.*;public class Q1 public static void main(String args) Scanner input = new Scanner (System.in); System.out.print(Enter a degree in Celsius: ); double c = input.nextDouble(); double f; f = 9.0 / 5 * c + 32; System.out.println(c + Celsius is + f + Fahrenheit); import java.util.*
2、;public class Q2 public static void main(String args) Scanner input = new Scanner (System.in); System.out.print(Enter an ASCII code: ); int num = input.nextInt(); char letter = (char) num; System.out.println(The character for ASCII code + num + is + letter); import java.util.*;public class Q3 public
3、 static void main(String args) Scanner input = new Scanner(System.in); System.out.print(Enter a number between 0 and 1000: ); int num = input.nextInt(); int unit = num % 10; int decade = num / 10 % 10; int hundred = num / 100; int sum = unit + decade + hundred; System.out.println(The sum of the digi
4、ts is + sum); import java.util.*;public class Q4 public static void main(String args) final int MAXSIZE = 100; int student = new intMAXSIZE; int best = 0; Scanner input = new Scanner(System.in); System.out.print(Enter the number of students: ); int num = input.nextInt(); System.out.print(Enter + num
5、 + scores: ); for(int i = 0 ; i best) best = studenti; for(int i = 0 ; i = best - 10) System.out.println(Student + i + score is + studenti + and grade is A); else if(studenti = best - 20) System.out.println(Student + i + score is + studenti + and grade is B); else if(studenti = best - 30) System.out
6、.println(Student + i + score is + studenti + and grade is C); else if(studenti = best - 40) System.out.println(Student + i + score is + studenti + and grade is D); else System.out.println(Student + i + score is + studenti + and grade is F); import java.util.*;public class Q1 public static void main(
7、String args) String represent = new String3; Scanner input = new Scanner(System.in); Random random = new Random(); represent0 = scissor; represent1 = rock; represent2 = paper; System.out.print(scissor (0), rock (1), paper (2): ); int com = random.nextInt(3); int user = input.nextInt(); if(com = user
8、) System.out.println(The computer is + representcom + . You are + representuser + too. It is a draw.); else if(com = 0&user = 1)|(com = 1&user = 2)|(com = 2&user = 0) System.out.println(The computer is + representcom + . You are + representuser + . You win); else System.out.println(The computer is +
9、 representcom + . You are + representuser + . You lose); import java.util.*;public class Q2 public static void main(String args) Scanner input = new Scanner(System.in); boolean result; System.out.print(Enter three edges: ); double a = input.nextDouble(); double b = input.nextDouble(); double c = inp
10、ut.nextDouble(); System.out.print(Can edges + a + , + b + , and + c + form a triangle? ); if(a + b c & a + c b & b + c a) result = true; else result = false; System.out.println(result); import java.util.*;public class Q3 public static void main(String args) int digit = new int9; Scanner input = new
11、Scanner(System.in); System.out.print(Input an integer to calculate ISBN(Only nine digits): ); int data = input.nextInt(); int checksum = 0; int temp = data; for(int i = 0 ; i = 0 ; i-) System.out.print(digiti); if(checksum = 10) System.out.println(X); else System.out.println(checksum); import java.u
12、til.*;public class Q1 public static void main(String args) print(chicks,chick); print(cows,moo); print(ducks,quack); print(pigs,oink); public static void print(String word1,String word2) System.out.println(Old MacDonald had a farm Old MacDonald had a farm, e i e i o); System.out.println(And on his f
13、arm he had some + word1 + , e i e i o); System.out.println(with a + word2 + word2 + here and a + word2 + + word2); System.out.println(there); System.out.println(here a + word2 + there a + word2); System.out.println(everywhere a + word2 + + word2); System.out.println(Old MacDonald had a farm, e i e i
14、 o); System.out.println(); import java.util.*;public class Q2 public static void main(String args) Scanner input = new Scanner (System.in); System.out.print(Input how many Fibonacci numbers you want to print: ); int num = input.nextInt(); for(int i = 1 ; i = 0 ; i-) if(hexai 9) switch(hexai) case 10
15、:System.out.print(A);break; case 11:System.out.print(B);break; case 12:System.out.print(C);break; case 13:System.out.print(D);break; case 14:System.out.print(E);break; case 15:System.out.print(F);break; else System.out.print(hexai); System.out.println(); import java.util.*;public class Q4 public sta
16、tic void main(String args) for(int i = 3 ; i 998 ; i += 2) int j = i + 2; if(Prime(i) & Prime(j) System.out.println( + i + , + j + ); public static boolean Prime(int num) for(int i = 2 ; i = Math.sqrt(num) ; i+) if(num % i = 0) return false; return true; import java.util.*;public class CoutingOccurr
17、enceOfNumbers static final int MAXSIZE = 100; public static void main(String args) Scanner input = new Scanner(System.in); int array1 = new intMAXSIZE; int array2 = new int101; System.out.print(Enter the integers betwenn 1 and 100:); for(int i = 0; i 101; i+) array2i = 0; for(int i = 0; ; i+) array1
18、i = input.nextInt(); array2array1i+; if(array1i = 0) break; for(int i = 1; i 101; i+) if(array2i != 0) System.out.println(i + occurs + array2i + times); import java.util.*;public class EliminatingDuplicate static int length = 0; public static void main(String args) int numbers = new int10; System.ou
19、t.print(Enter ten numbers:); int result = eliminatingDuplicates(numbers); System.out.print(The distinct numbers are:); for(int i= 0 ; i = length ; i+) System.out.print(resulti + ); public static int eliminatingDuplicates(int numbers) Scanner input = new Scanner(System.in); numbers0 = input.nextInt()
20、; int temp; boolean rep = true; for(int i = 1 ; i 10 ; i+) temp = input.nextInt(); for(int j = 0 ; j = length ; j+) if(numbersj = temp) rep = false; break; if(rep) numbers+length = temp; rep = true; return numbers; import java.util.*;public class IdenticalArrays public static void main(String args)
21、Scanner input = new Scanner(System.in); int n1,n2; System.out.print(Enter list1:); n1 = input.nextInt(); int list1 = new intn1; for(int i = 0 ; i n1 ; i+) list1i = input.nextInt(); System.out.print(Enter list2:); n2 = input.nextInt(); int list2 = new intn2; for(int i = 0 ; i n2 ; i+) list2i = input.
22、nextInt(); System.out.println(Two lists are + (isIdentical(list1,list2) ? identical : not identical); public static boolean isIdentical(int list1,int list2) Arrays.sort(list1); Arrays.sort(list2); if(Arrays.equals(list1,list2) return true; else return false; public class NSideRegularPolygon public s
23、tatic void main(String args) RegularPolygon polygon1 = new RegularPolygon(6,4); RegularPolygon polygon2 = new RegularPolygon(10,4,5.6,7.8); System.out.println(Polygon1:); System.out.println(perimeter: + polygon1.getPerimeter() + area: + polygon1.getArea(); System.out.println(Polygon2:); System.out.p
24、rintln(perimeter: + polygon2.getPerimeter() + area: + polygon2.getArea(); class RegularPolygon int n; double side; double x; double y; RegularPolygon() n = 3; side = 1; x = 0; y = 0; RegularPolygon(int n0,double s0) n = n0; side = s0; x = 0; y = 0; RegularPolygon(int n1,double s1,double x1,double y1) n = n1; side = s1; x = x1; y = y1; double getPerimeter() return n * sid
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1