Tích 2 số
Tính TổngCode:/** * @(#)tich.java * * * @author * @version 1.00 2011/1/18 */ import java.util.Scanner; public class tich { /** * Creates a new instance of <code>tich</code>. */ public tich() { } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int c = a*b; System.out.print("tong la:"+c); } }
Số nguyên tốCode:import java.util.Scanner; public class Tinhtong { /** * Creates a new instance of <code>songuyen</code>. */ public Tinhtong() { } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int c = a+b; System.out.print("tong la:"+c); } }
Dãy fibonaxiCode:/** * @(#)songuyento.java * * * @author * @version 1.00 2011/1/18 */ import java.util.*; public class songuyento { /** * Creates a new instance of <code>songuyento</code>. */ public songuyento() { } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int i,s=0; Scanner a=new Scanner(System.in); int n=a.nextInt(); if (n==0||n==1) { System.out.print(n+" ko phai la so nguyen to");return;} if(n==2) {System.out.print(n+" la so nguyen to");return;} for(i=2;i<=n/2;i++) if(n % i == 0) {s=1; break;} if(s==0) System.out.print(n+" la so nguyen to"); else System.out.print(n+" ko phai la so nguyen to"); } }
Chu vi, diện tíchCode:/** * @(#)fibonaci.java * * * @author * @version 1.00 2011/1/18 */ import java.util.*; public class fibonaci { /** * Day fibonaci */ public static int nhap() { Scanner s= new Scanner(System.in); boolean check=false; int n=0; return(n); } static boolean kt_fibo(int n) { boolean kt=true; if(n<=1) return false; int f1=1,f2=1,fi=2; while(!false) { int t=f1; f1=f2; f2=t+f2; kt=false; break; } return kt; } public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Nhap bao nhieu phan tu cua mang "); //Nhap so luong phan tu int k = s.nextInt(); int [] dayso; //khai bao mang dayso = new int [100]; System.out.println("Nhap mang "); for(int i=0;i<=k-1;i++) { System.out.println("Nhap so phan tu thu " + i); dayso [i]= nhap(); } //Xuat mang System.out.println("Cac phan tu la so fibonaci cua mang "); for(int i =0;i<=k-1;i++){ if(kt_fibo(dayso[i])) System.out.println("So " + dayso [i] + " la so fibonaci"); else System.out.println("So " + k + " khong phai la so fibo"); } } }
Code:import java.util.scanner; class BAI1 { public static void main(String[] args) { Scanner s = new Scanner(System.in); float pi=3.14; float a = r.nextInt(); system.out.println("nhap vao ban kinh r :"); double cv=2*pi*r; double dt=pi*r*r; system.out.println("chu vi la :"+cv); system.out.println("dien tich la :" +dt); } }
Tham khảo thêm tại đây
--------------------------------------------------
Xem các chủ đề cùng chuyên mục:
- Frame & GridbagLayout trong java 21/09/2011
- Thành Phần Cú Pháp Trong Javascript 08/09/2009
- Tập hợp những đoạn java script hay. [vẫn còn đang cập nhật ] 08/08/2009
- Make noise Image 24/09/2011
- Xin Ebook JAVA 14/01/2011
- Cho mình hỏi về đoạn javascript này 16/11/2011
- Bài tập về sắp sếp mảng trong JAVA 14/09/2011
- pác nào có đầy đủ đề và bài giải của java cơ bản từ bài thực hành số 1 tới 7 và 2 bài tổng hợp up... 02/07/2011
- Java là gì? Và tại sao bạn cần quan tâm? 29/11/2009
- Một số bài tập Java Căn bản 27/10/2011
+2 EXP






interpol





Trả Lời Với Trích Dẫn