if(min>a[j]){
min= a[j];
key= j;
}
}
return (key);
}
public static float maxFloat(float a[], int n){
float max= a[0];
}
return (max);
}
public static void main(String[] args) {
int n,i;
System.out.println(" nhap="" n=");
n= nhap();
float[] array= new float[n];
for(i=0 ; i
System.out.println(" phan="" tu="" thu="" "="" +(i+1)+"="" ");=""
array[i]= nhapFloat();
}
i =0;
System.out.println("Sap xep theo thu tu tang dan");
while(i
System.out.println(" "+array[viTriMinFloat(array, n)]);
array[viTriMinFloat(array, n)]= maxFloat(array, n);
i++;
}
}
}
for(int j=0 ; j
if(min>a[j]){
min= a[j];
key= j;
}
}
return (key);
}
public static float maxFloat(float a[], int n){
float max= a[0];
for(int j=0 ; j
if(max
}
return (max);
}
public static void main(String[] args) {
int n,i;
System.out.println("Nhap n= ");
n= nhap();
float[] array= new float[n];
for(i=0 ; i
System.out.println("Nhap phan tu thu " +(i+1)+" ");
array[i]= nhapFloat();
}
i =0;
System.out.println("Sap xep theo thu tu tang dan");
while(i
System.out.println(" "+array[viTriMinFloat(array, n)]);
array[viTriMinFloat(array, n)]= maxFloat(array, n);
i++;
}
}
}
Lesson 18:
package bai18;
import java.util.*;
public class Main {
public static void main(String[] args)
{ Scanner input= new
Scanner(System.in);
System.out.println("Nhap vao 1 xau: ");
String str= input.nextLine();
StringTokenizer strToken= new
StringTokenizer(str, " "); System.out.println("So cac tu trong xau la: "+strToken.countTokens());
}
}
Lesson 19:
package bai19;
import java.util.Scanner;
public class Main {
public static int nhap(){
Scanner input= new Scanner(System.in);
boolean check= false;
int n=0;
while(!check){
System.out.print(" ");
try{
n= input.nextInt();
check= true;
}catch(Exception e){
System.out.println("Ban phai nhap so! hay nhap lai.");
input.nextLine();
}
}
return (n);
}
public static boolean checkSNT(int n){
if(n>1){
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
else return false;
}
public static int tongChuSo(int n){
int T=0;
while(n>0){
T+= n%10;
n/= 10;
}
return (T);
}
public static void main(String[] args) {
System.out.print("Nhap S= ");
int s= nhap(); int i,count=0;
System.out.println("Cac so nguyen to co tong cac chu so co tong bang "+s+" la: ");
for(i=10000 ; i<=99999 ; i++){
if(checkSNT(i)){
if(tongChuSo(i)== s) {
System.out.println(" "+i);
count++;
}
else continue;
}
}
System.out.println("Co "+count+" so thoa man");
}
}
Lesson 20:
package bai20;
import java.util.Scanner;
public class Main {
public static int nhap(){
Scanner input= new Scanner(System.in);
boolean check= false;
int n=0;
while(!check){
System.out.print(" ");
try{
n= input.nextInt();
check= true;
}catch(Exception e){
System.out.println("Ban phai nhap so! hay nhap lai.");
input.nextLine();
}
}
return (n);
}
//Ham kiem tra so nguyen to
public static boolean checkSNT(int n){
if(n>1){
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
else return false;
}
public static void main(String[] args) {
System.out.print("Nhap n= ");
int n= nhap();
int[] f= new int[n];
f[0]= 1; f[1]= 1;
int i=1,count=1;
System.out.print("Cac so Fibonanci nho hon "+n+" la so nguyen to: n 1");
while(f[i]
if(checkSNT(f[i])){
System.out.print(" "+f[i]);
count++;
} i++;
f[i]= f[i-1] + f[i-2];
}
System.out.println("n Co "+count+" so thoa man");
}
}
System.out.print("Cac so Fibonanci nho hon "+n+" la so nguyen to: n 1");
while(f[i]
if(checkSNT(f[i])){
System.out.print(" "+f[i]);
count++;
} i++;
f[i]= f[i-1] + f[i-2];
}
System.out.println("n Co "+count+" so thoa man");
}
}
Lesson 21:
package bai21;
import java.util.Scanner; public class Main {
public static int nhap(){
Scanner input= new Scanner(System.in); boolean check= false;
int n=0; while(!check){
System.out.print(" "); try{
n= input.nextInt(); check= true;
}catch(Exception e){
System.out.println("Ban phai nhap so! hay nhap lai."); input.nextLine();
}
}
return (n);
}
public static int tongChuSo(int n){ int T=0;
while(n>0){
T+= n%10;
n/= 10;
}
return (T);
}
//Ham kiem tra so nguyen to
public static boolean checkSNT(int n){ if(n>1){for(int i=2;i<=Math.sqrt(n);i++){ if(n%i==0) return false;
}
return true;
}
else return false;
}
public static void phanTich(int n){
int i=2; while(n>1){
if(checkSNT(i)){
if(n%i==0){
System.out.print(i+"."); n/=i;
}
else i++;
}
else i++;
}
}
public static void main(String[] args) {
System.out.print("Nhap n");
int n= nhap(); System.out.print("n= 1" ); phanTich(n);
System.out.println("Tong cac chu so cua "+n+" la: "+tongChuSo(n));
}
}
Lesson 22:
package bai22;
import java.util.Scanner; public class Main {
public static int nhap(){
Scanner input= new Scanner(System.in); boolean check= false;
int n=0; while(!check){
System.out.print(" "); try{
n= input.nextInt(); check= true;
}catch(Exception e){
System.out.println("Ban phai nhap so! hay nhap lai."); input.nextLine();
}
}
return (n);
}
public static boolean checkSNT(int n){
if(n>1){
for(int i=2;i<=Math.sqrt(n);i++){ if(n%i==0) return false;}
return true;
}
else return false;
}
public static void lietKeUoc(int n){
int count=0;
System.out.print("nCac uoc cua "+n+" la:"); for(int i=1 ; i<=n ; i++){
if(n%i==0) {
System.out.print(" "+i); count++;
}
}
System.out.println("nCo "+count+" uoc");
}
public static void lietKeUocSNT(int n){
int count=0;
System.out.print("nCac uoc cua "+n+" la:"); for(int i=1 ; i<=n ; i++){
if(n%i==0 && (checkSNT(i))) { System.out.print(" "+i); count++;
}
}
System.out.println("nCo "+count+" uoc la so nguyen to");
}
public static void main(String[] args) {
System.out.print("Nhap n");
int n= nhap(); lietKeUoc(n); lietKeUocSNT(n);
}
}
Lesson 23:
package bai23;
import java.util.Scanner; public class Main {
public static int nhap(){
Scanner input= new Scanner(System.in); boolean check= false;
int n=0; while(!check){
System.out.print(" "); try{
n= input.nextInt(); check= true;
}catch(Exception e){
System.out.println("Ban phai nhap so! hay nhap lai."); input.nextLine();
}
}
return (n);
}
public static boolean checkSNT(int n){
if(n>1){
for(int i=2;i<=Math.sqrt(n);i++){ if(n%i==0) return false;
}
return true;
}
else return false;
}
public static void lietKeSNT(int n){
int i=1,count=0;
System.out.println("Cac so nguyen to nho hon "+n+" la: "); while(i
if(checkSNT(i)){
System.out.print(" "+i); count++;
} i++;
}
System.out.println("n Co "+count+" so thoa man");
}
public static void main(String[] args) {
System.out.print("Nhap n");
int n= nhap(); lietKeSNT(n); int[] f= new int[n]; f[0]= 1; f[1]= 1;
int i=1;
System.out.print("Cac so Fibonanci nho hon "+n+" la : n 1"); while(f[i]
System.out.print(" "+f[i]);
i++;
f[i]= f[i-1] + f[i-2];
}
System.out.println("n Co "+i+" so thoa man");
}
}
System.out.println("Cac so nguyen to nho hon "+n+" la: "); while(i
if(checkSNT(i)){
System.out.print(" "+i); count++;
} i++;
}
System.out.println("n Co "+count+" so thoa man");
}
public static void main(String[] args) {
System.out.print("Nhap n");
int n= nhap(); lietKeSNT(n); int[] f= new int[n]; f[0]= 1; f[1]= 1;
int i=1;
System.out.print("Cac so Fibonanci nho hon "+n+" la : n 1"); while(f[i]
System.out.print(" "+f[i]);
i++;
f[i]= f[i-1] + f[i-2];
}
System.out.println("n Co "+i+" so thoa man");
}
}
System.out.println("Cac so nguyen to nho hon "+n+" la: "); while(i
if(checkSNT(i)){
System.out.print(" "+i); count++;
} i++;
}
System.out.println("n Co "+count+" so thoa man");
}
public static void main(String[] args) {
System.out.print("Nhap n");
int n= nhap(); lietKeSNT(n); int[] f= new int[n]; f[0]= 1; f[1]= 1;
int i=1;
System.out.print("Cac so Fibonanci nho hon "+n+" la : n 1"); while(f[i]
System.out.print(" "+f[i]);
i++;
f[i]= f[i-1] + f[i-2];
}
System.out.println("n Co "+i+" so thoa man");
}
}
Lesson 24:
package bai24;
import java.util.Scanner; public class Main {
public static int nhap(){
Scanner input= new Scanner(System.in);
boolean check= false;
int n=0;
while(!check){
System.out.print(" ");
try{
n= input.nextInt();
check= true;
}catch(Exception e){
System.out.println("Ban phai nhap so! hay nhap lai.");
input.nextLine();
}
}
return (n);
}
public static boolean checkSNT(int n){
if(n>1){
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
else return false;
}
public static void inMT(int[][] A, int n, int m){
int i,j;
for(i=0 ; i
System.out.print(4 ★ | 1 Vote
You should read it
- Write and run Java code on the computer for the first time
- Download and install Java on the computer
- How to Compile a Java Program
- 4 ways to write multi-threaded code in Java
- Which career Java programming options are waiting for you?
- eQuiz - Multiple choice quiz about JAVA
- What is JAVA file? How to open, edit and convert JAVA files
- 9 things Java programmers should know in 2018 if they want a successful career
May be interested
Please download VnDoc's Exercises app to make learning easier
solving exercises with vndoc is an application that helps students learn good subjects. download this application to your phone, parents and students from grade 1 - 12 will have more instructions to solve the textbook exercises, homework exercises in mathematics, vietnamese, language arts, english .
C ++ exercises about IF ELSE
in the previous c ++ exercise, we introduced you to read c ++ exercises about variables and data types. this time, there are 8 c ++ exercises about if else for you to practice and proficiently use if, else in c ++, please watch it.
5 interesting features about Java 9 you may not know yet
let's tipsmake.com learn 5 interesting features about java 9 you may not know in the article below!
Test on JAVA test P5
do you like java programming and want to learn useful knowledge to apply to work? to meet the needs of readers, network administrators have collected and sent a series of quiz questions about java programming. invite your reference.
JAVA test on P4
the multiple choice questions about java programming will provide you with useful knowledge in the process you apply to learning as well as working with java. invite your reference.
Learn about Java Driver in MongoDB
in the following article, we will introduce you some basic features of mongodv java driver as well as how to deploy and apply in practice.
JAVA test on P6
multiple choice questions about java programming give you useful knowledge. if you love java programming, don't skip the series of interesting tests below by network administrator.
eQuiz - Multiple choice test on Java Swing Practice - Part 2
in the previous article, we introduced you to part 1 of the test of basic java swing knowledge. and below is part 2 of the quiz series with 14 questions, including some questions with many different answer options.
What is JAVA file? How to open, edit and convert JAVA files
a file with a .java extension is (or sometimes also used in .jav format) is a java source file written in the java programming language.
More than 100 Python exercises have solutions (sample code)
more than 100 python code examples are shared by guy zhiwehu on github, however, the solution of this series is written on the old python version. following tipsmake.com will be vietnameseized and edited to suit python 3.x to help you learn and practice python.