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
4 ways to write multi-threaded code in Java
multithreading is a method of writing code to execute multiple tasks in parallel. java offers great support for multi-threaded code writing right from java 1.0 version. recent improvements in java have increased the number of ways that code is structured to combine multiple threads in java programs.
13 important SQL statements Programmer needs to know
13 important sql commands that you will have to use frequently when manipulating data tables. if you are a programmer, you need to memorize these sql statements.
Top 10 HTML tags that each blog and website owner should know
web in the world is coded in many different languages. however, there is a language that can be found on all those sites, hypertext markup language, commonly referred to as html.
17 simple HTML codes you can learn in 10 minutes
although modern web pages are often built with user-friendly interfaces, it's good to know some basic html . if you know the following 17 tags, you can create a basic web page from scratch or tweak the code created by an application like wordpress.
Website construction: HTML and XHTML tricks
this article will introduce you to some of the widely used html and xhtml tricks.