This is the 8th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Java Learning Notes series — Sun Bujian 1208

【 Detail + super basic 】Java- Learning Notes 01

【 Detail + super basic 】Java- Study Notes 02

【 Detail + super basic 】Java- Study Notes 03

【 Detail + super basic 】Java- Study Notes 04

【 detail + super basic 】Java- Study Notes 05

Ongoing updates….

Three, Java basic topic exercises

T1: use the nesting of conditional operators to complete this question: students whose grades are >=90 are represented by A, students whose grades are between 60-89 are represented by B, and students whose grades are below 60 are represented by C.

public class T1 { public static void main(String args[]){ int score=90; if(score>=90){ System.out.println("A"); } else if(score>=60){ System.out.println("B"); } else{ System.out.println("C"); }}}Copy the code

T2: Input a number greater than 0 from the keyboard and save it to the int variable count, indicating the number of int array, let’s say count, then read count from the keyboard, save it to an int array, finally, output the sum and average of all elements in the array.

public class T2 { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int count=sc.nextInt(); int [] array=new int[count]; for (int i = 0; i <count ; i++) { array[i]=sc.nextInt(); } for (int i = 0; i <count ; i++) { if(suShu(array[i])){ System.out.println(" "+array[i]); } } } public static boolean suShu(int s){ for (int i = 2; i <=s ; i++) { if(s%i==0){ return false; } } return true; }}Copy the code

T3: Enter two positive integers m and n and find their greatest common divisor and least common multiple.

public class T3 { public static void main(String args[]){ gcdlcm a =new gcdlcm(); Println (" +a.gcd(10, 16)); println(" +a.gcd(10, 16)); Println (" the least common multiple of two numbers is: "+ a.cm (16, 10)); }} class GCDLCM {int GCD (int m,int n){if(m<n){int temp=n; n=m; m=temp; } if(m%n==0){ return n; } else{ m%=n; return gcd(m,n); } } int lcm(int m,int n){ int i=1; If (m<n){// int temp=n; n=m; m=temp; } int lcm=m; while(lcm%n! =0){ lcm=m*i; i++; } return lcm; }}Copy the code

T4: Print out all the “daffodil numbers”, a three-digit number whose cube sum is equal to the number itself. Such as:

153 is a “daffodil number” because 153=1 to the third power +5 to the third power +3 to the third power.

public class T4 { public static void main(String args[]){ int a,sum; Int I,j,k; For (a=100; a=100; a<=999; a++){ i=a/100; j=(a-i*100)/10; k=a-i*100-j*10; sum=i*i*i+j*j*j+k*k*k; If (sum==a) {system.out.println (sum); }}Copy the code

T5: have a pair of rabbits, from the 3rd month after being born each month to give birth to a pair of rabbits, little rabbit child grows to the 3rd month after each month to give birth to a pair of rabbits, if the rabbit is not dead, how many is the rabbit total number that asks each month?

In the first month, there were only one pair of rabbits, in the second month, there were only one pair of rabbits, in the third month, there were two pairs, in the fourth month, there were three pairs, in the fifth month, there were five pairs, in the sixth month, there were eight pairs, and in the seventh month, there were thirteen pairs.

Public class T5{public static void main(String args[]){ long arr[]=new long[36]; Arr [0]=arr[1]=1; System.out.println(" there are 1 pairs of rabbits in month 1 "+", "+" total is "+2 "); System.out.println(" there are 1 pairs of rabbits in month 2 "+", "+" total is "+2 "); for(i=2; i<=35; i++){ arr[i]=arr[i-1]+arr[i-2]; System. The out. Println (" first "+ I +" months have rabbit "+ arr [I] +" to "+", "+" the total "+ 2 * arr [I]); // The rule is that each number is the sum of the first two numbers}}}Copy the code

Welcome to subscribe column to invite you to drink a cup of Java, hope to bring convenience to friends in need, but also hope to get everyone’s attention and support.