Online to see 3 good Java Development engineers on the machine pen questions, there is no answer here to write the answer, for everyone reference.
1, a program, enter 10 integers, and put in the array, the first descending output all the number, and then statistics and output the number of positive, negative and zero
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/56/CA/wKioL1SOYM3hdwnyAAD5bEx1wM8292.jpg "title=" 051914 _1248_java1.png "alt=" Wkiol1soym3hdwnyaad5bex1wm8292.jpg "/>
PACKAGE&NBSP;CN. pigzhu.test;import java.util.scanner;/** * Console Enter 10 numbers and enter the number of positive and negative * @author Xiaoyezhu * */public class test{public static void main (String[] args) {int a[] = new int[10];int i = 0;int m = 0;int n = 0;/** * gets 10 numbers in the array, and calculates the number of positive and 0 by the way. */while (i != 10) {System.out.print ("Please enter" +i+ "number: "); Scanner scan = new scanner (system.in); Int input = scan.nextint (); I++;a[i-1] = input;//here the first number of arrays is a[1] so the number of i-1./** * 0 to be */if (input==0) {m++;} if (input<0) {n++;}} /** * the array for descending output */system.out.print ("number entered is: ");for (int j = 0; j < a.length-1; j++) {int temp;for (int k = 0; k < a.length-j-1; k++) {if (a[k]<a[k+1]) {Temp = a[k];a[k] = a[k+1];a[K+1] = temp;}}} for (int k = 0; k < a.length; k++) {System.out.print (a[k]+ " ");} System.out.println (); SYSTEM.OUT.PRINTLN ("Positive number has: " + (10-m-n) + " " + "negative numbers have: " +n+ " " + "0 are: "+m+");}}
2.
Implement a simple English-Chinese weather converter: Enter the weather condition in table 1 The first letter of the English word, according to the input to determine the weather conditions, and output the Chinese form of the weather. The user can re-enter the conversion and enter N to exit the system. Run effect 1 as shown.
Dry mania |
humid |
hot |
rain |
Dry |
Moisture |
Hot |
Rainy |
Table 1: Chinese and English comparison of weather conditions
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/56/CD/wKiom1SOYKbwo_Q-AAFkUAiVFY8302.jpg "title=" 051914 _1248_java2.png "alt=" Wkiom1soykbwo_q-aafkuaivfy8302.jpg "/>
Figure 1: Run effect
PACKAGE&NBSP;CN. pigzhu.test;import java.util.scanner;/** * implements a simple Chinese-English weather converter * @author xiaoyezhu * */public class test{public static void main (String[] args) { SYSTEM.OUT.PRINTLN ("****** welcome to the Mini converter ******");/** * while loop to get the weather converted */while (true) { System.out.print ("Please enter the first English letter of the Weather condition:"); Scanner scan = new scanner (system.in); String s = scan.next ();if (S.equals ("D")) {System.out.println ("dry");} else if (S.equals ("M")) {System.out.println ("damp");} else if (S.equals ("H")) {System.out.println ("hot");} else if (S.equals ("R")) {System.out.println ("Rain");} ELSE&NBSP;{SYSTEM.OUT.PRINTLN ("Input error, cannot convert!") ");} /** * continues y on the loop, n jumps out of the loop. */system.out.print ("Do you want to continue?") (y/n): "); Scanner scan2 = new scanner (system.in); String s2 = scan2.next ();if (S2.equals ("n")) {break;}} System.out.println ("Exit system!");}}
3 . Use the Java language to implement.
Automatically generates 10 integers (1~100) to find the maximum and minimum values in the generated sequence. Operating effect:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/56/CA/wKioL1SOYayDnCfQAADlV8uWQjU568.jpg "title=" 051914 _1248_java3.png "alt=" Wkiol1soyaydncfqaadlv8uwqju568.jpg "/>
Figure 1: Run effect
Requirements:
Use the Java language;
The sort method of the arrays class is not allowed.
PACKAGE&NBSP;CN. Pigzhu.test;import java.util.hashset;import java.util.iterator;import java.util.random;import java.util.Set;/** * randomly generate 10 numbers to select the maximum and minimum * @author xiaoyezhu * */public class test{/** * the best way to do that is to choose the sort pattern * @param args */public static void main (String[] args) {/** * randomly generated 10 numbers exist in set output */system.out.println ("Randomly generated series is: "); Random r = new random (); Set<integer> set = new hashset<integer> (); while (Set.size ()!=10) {Set.add ( R.nextint (100) +1);} /** * Traverse out 10 numbers */iterator<integer> it = set.iterator (); int i = 0;int a[] = new int[10] ;while (It.hasnext ()) {a[i] = it.next (); i++; System.out.print (a[i-1]+ " ");} SYSTEM.OUT.PRINTLN ();/** * use a similar selection method to find the maximum, the smallest also the same */int temp = a[0];for (int j = 0; j < a.length; j++) {if (a[j]>temp) {temp = a[j];}} System.out.println ("The largest number of this series is: " +temp);temp = a[0];for (int j = 0; j < a.length; j++) {if (a[j]<temp) {temp = a[j];}} System.out.println ("The smallest number of this series is: " +temp);}}
Hope to help everyone!
Java Development Engineer on-machine pen test