比較笨就把所有的都復制過來吧,以后再整理:
//for(表達式1,條件表達式;表達式2){
// 語句塊
//}
public class 視頻求是某多少天 {
public static void main(String[] args) {
int i = 1;
for (int j = 1; j <=100; j++) {
if(j*)
}
}
}
public class 創建新方法 {
public static void main(String[] args) {
// 不能寫在平行,搖寫在花括號外面,因為兩個方法是平行的
}
/**
* 判斷閏年
* @param year 年份
* @return 是閏年返回true否則返回false
*/
public static boolean isleapYear(int year) {
return year % 4 == 0 && year % 100 !=0||year %400 == 0 ;
}
// 兩個都是整數用,號隔開(int year,int month)
public static int daysOfmonth(int year,int month){
int days;
switch (month) {
case 2:
days = isleapYear(year)?29:28;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
default:
days = 31;
break;
}
return days;
}
}
import java.util.Scanner;
public class NIanFen1 {
public static void main(String[] args) {
// 輸入年月日計算,是哪個年份的多少天
// 設置未知數年、月、日、輸入的求和
Scanner sc = new Scanner(System.in);
System.out.print("請輸入年份:");
int year = sc.nextInt();
System.out.print("請輸入月份:");
int month = sc.nextInt();
System.out.print("請輸入日:");
int day = sc.nextInt();
int count = 0;
int days = 0;
// 未知數為0,樓下就是年大于(輸入的數DAYS),月份>0&&<13&&day
if (year > 0 && month > 0 && month < 13 && day > 0 && day < 32) {
for (int i = 1; i < month; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2: {
if ((year % 4 == 0 && year % 1 != 0) ||
(year % 400 == 0)) {
days = 29;
} else {
days = 28;
}
break;
}
}
count = count + days;
}
count = count + day;
System.out.println(year + "年" + month + "月" + day + "日是" + year + "年的第" + count + "天");
} else
System.out.println("數據輸入錯誤!");
}
}
import java.time.Year;
import java.util.Scanner;
public class NianFen2 {
private static final boolean Year = false;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("請輸入年份:");
int year = sc.nextInt();
System.out.print("請輸入月份:");
int month = sc.nextInt();
System.out.print("請輸入日:");
int day = sc.nextInt();
int count =year+month+day ;
//int days = year-;
System.out.print("請輸入年份:");
int year2 = sc.nextInt();
System.out.print("請輸入月份:");
int month2 = sc.nextInt();
System.out.print("請輸入日:");
int day2 = sc.nextInt();
int count2 = 0;
int days = sc.nextInt();
System.out.println(days);
int count1 =year2+month2+day2 ;
int jl=count-count1;
int j1= sc.nextInt();
System.out.println(jl+"nian");
}
}
//int a = Year -Year1;
//
//int day = sc.nextInt();
//int count = 0;
//int days = 0;
//Scanner sc = new Scanner(System.in);
//System.out.print("請輸入年份:");
//int year = sc.nextInt();
//System.out.print("請輸入月份:");
//int month = sc.nextInt();
//System.out.print("請輸入日:");
//int day = sc.nextInt();
import java.util.Scanner;
public class NianFen {
public static void main(String[] args) {
// Scanner input = new Scanner(System.in);
// System.out.print("請輸入兩個數");
// int a=input.nextInt();
// int b=input.nextInt();
// System.out.print(a>b?a:b);
// 練習:輸入一個年份判斷是不是閏年
Scanner input = new Scanner(System.in);
System.out.print("請輸入年份:");
if (input.hasNextInt()) {
int year = input.nextInt();
if (year>0){
boolean isleapYear = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
System.out.println(year + "年" + (isleapYear ? "是" : "不是") + "閏年");
} else {
System.out.println("年份必須是整數");
}
// System.out.println("逗比曾加新請輸入整數年份,乖!");
}
input.close();
}
}
import java.util.Scanner;
public class NIanFen1a {
// 如果程序中出現重復的功能或者相對來說獨立的功能,那么應該講這些功能單獨寫成一個方法
// 對照MAIN方法寫出來。如public sastic ? isleapyear(int year)
// 因為要判定這個年份是不是閏年,因數?就的用真假方法。說以如下備注,記得是個方法還有個花括號
// public sastic boolean isleapyear(int year){
// 寫個這樣里面寫year就好了 如右if (isleapYear(year)){
public static boolean isleapYear(int year){
return year % 4 == 0 && year % 100 !=0||year %400 == 0 ;
}
public static int daysofmonth(int year,int month){
// 年個月的方法
int month =
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("請輸入年份:");
int year = sc.nextInt();
System.out.print("請輸入月份:");
int month = sc.nextInt();
System.out.print("請輸入日:");
int day = sc.nextInt();
int total =0;
// 累加變量total
for (int i = 1; i < month; i++) {
//
if(i==2){
if (isleapYear(year)){
total +=29;
}
else{
total+=28;
}}else if(i == 4||i==6||i==9||i==11){
total+=38;}
else {
total +=31;
}
}
total +=day;
System.out.printf("%d年%d月");
}
}
}
import java.util.Scanner;
public class SanJiaoXing {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.println("請輸入三角形的三條邊長:");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
input.close();
//boolean isvalid =(a+b>c&&b+c>a&&a+c>b)
// if (isvalid)
if (a+b>c&&b+c>a&&a+c>b){
double perimetar = a+b+c;
double half = perimetar/2;
double area = Math.sqrt
(half(half-a)(half-b)*(half-c));
System.out.printf("zhouchang:%.2f\n", perimetar);
System.out.printf("mianji:%.2f\n", area);
}
else{
System.out.println("不能構成三角型");
}
}
}
package 個人練習從0開始異世界;
import java.util.Scanner;
public class 試用 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// 掃描器
int money = 1000;
do{
System.out.println("您的總資產為:¥"+money+"元");
boolean bet;
do {
System.out.println("請下注:");
bet = input.nextLine() != null;
int a = (int) (Math.random() * 6 + 1);
// 0到1的開區間的隨機數,強制轉換。
int b = (int) (Math.random() * 6 + 1);
// a、b隨機產生的色子點數
int s = a + b;
// 設置s為搖出來的點數!
System.out.println("請通過按數字1進行搖色子");
// 請顧客按鍵操作搖色子
int number = input.nextInt();
// 設置一個數量為number,表示
if (number == 1) {
// 如果number等于1著執行花括號{}里面的,
// 如果不成立就執行else,這里沒有else就不執行,執行Switch類的條件
boolean over;
// boolean over表示樓下的運算成立不,
// 都是先定義變量over是否成立在使用。樓下有over
switch (s) {
// 分支結構:switch{case、case、N個case然后不適用后用關閉使用break;
case 7:
case 11:
System.out.println("玩家勝");
break;
case 2:
case 3:
case 12:
System.out.println("莊家勝 ");
break;
default:
// 當前面的情況case都不成立的時候進行default
do {
//
a = (int) (Math.random() * 6 + 1);
b = (int) (Math.random() * 6 + 1);
// 上面已經備注了一次a和b說以現在直接命名就可以了
int sum = a + b;
// 設置一個數為sum和上面S一樣的(int s=a+b)。
if (sum == 7) {
// 和樓上分支一樣用if和else if和else表示分支情況
// 如果不成立就執行else
System.out.println("莊家勝");
over = false;
} else if (sum == s) {
System.out.println("玩家勝");
over = false;
} else {
System.out.println("沒有分出勝負,繼續進行");
over = true;
}
} while (over);
break;
} while (bet);
// 循環里面可以再放循環。
}
}}
package 個人練習從0開始異世界;
public class WhileXunHuan {
// while循環
public static void main(String[] args) {
int s = 999;
// 先用S代表命名定義一個值
int i = 0;
// 當前次數
while (i<s) {
// 用whlie關鍵字表示,括號里面是(表達式)
// i如果小于S,表示成立可執行。
System.out.println("我愛你");
i++;
}
}
}
package 個人練習從0開始異世界;
public class LianXiHanZi {
// 輸入你想顯示的字,以下會顯示出你輸入的字和字之前的所有字體。如下鞠之前所有文字和鞠
public static void main(String[] args) {
// ASCII
for (int i = 0; i <=128; i++) {
System.out.println((char)i);
}
// GBK
char start = '-' ;
char end = '鞠';
for (int i = start; i <=end; i++) {
System.out.println((char)i);
}
}
}
package 個人練習從0開始異世界;
public class LianXi3a {
public static void main(String[] args) {
int gj;
int mj;
int xj;{
// 設置公雞,母雞小雞未知數,然后100元可以買20只公雞,33只母雞.....
for(gj=0;gj<=20;gj++) {
for(mj=0;mj<=33;mj++) {
for(xj=0;xj<=99;xj+=3){
if(gj+mj+xj==100&&5gj+3mj+xj/3==100){
System.out.printf("公雞:%d,母雞:%d,小雞:%d\n",gj,mj,xj);
} }}}}}}
package 個人練習從0開始異世界;
//5個人去打魚,a第一天起來分成了5分丟掉了多余的1條,
//b以為沒分又分成了5份拿走了自己的,多了一條也丟掉了,這個問題用窮舉法
//習題2,找1到100的完美數
//6=1+2=3
//28=1+2+4+7+14
public class LIanXi3 {
public static void main(String[] args) {
for (int gj = 0; gj <=22; gj++) {
for (int mj = 0; mj < 33; mj++) {
int xj = 100-gj-mj;
if (5*gj+3*mj+xj/3==100&&xj%3==0) {
System.out.printf("公雞:%d,母雞:%d,小雞:%d");
}
}
package 個人練習從0開始異世界;
public class LianXi2 {
// 打印一個乘法口訣表(九九表)
public static void main(String[] args) {
// 設置一個未知數為i,J,i和J=任何數字
for (int i = 1; i <=9; i++) {
for (int j = 1; j <=9; j++) {
System.out.printf("%d%d=%d\t",i,j,ji);
}
System.out.println();
}
}
}
package 個人練習從0開始異世界;
public class LianXi1 {
public static void main(String[] args) {
boolean n = true;
for (int i = 1; i <= 100; i++) {
for (int j = 2; j <= j - 1; j++) {
// 或for (int j = 2; j <=math.sqrt(n); j++) {
if (i % j == 0) {
n = false;
break;
}
}
if (n) {
System.out.println(i);
}
}
package 個人練習從0開始異世界;
import java.util.Scanner;
import javax.print.DocFlavor.INPUT_STREAM;
public class LianXi {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入一個正整數:");
// 檢查2~(n-1)之間有沒有n的因子
int n = input.nextInt();
boolean isprime=true;
// 先假設N是素數
for(int i = 2; i<=n-1; i++){
if(n%i==0){
isprime=false;
break;
}
}
package 個人練習從0開始異世界;
import java.util.Random;
public class C1Youxi {
/**
*
一個簡單的賭博游戲,游戲規則如下:
*玩家擲兩個骰子,點數為1到6,如果第一次點數和為7或11,則玩家勝,
*如果點數和為2、3或12,則玩家輸,
*如果和為其它點數,則記錄第一次的點數和,然后繼續擲骰,直至點數和等于第一次擲出的點數和,則玩家勝,
*如果在這之前擲出了點數和為7,則玩家輸。
*it looks difficult,but it's easy actually
*/
public static void main(String[] args) {
CrapsGame cg=new CrapsGame();
cg.begin();
}
package 個人練習從0開始異世界;
import javax.swing.plaf.synth.SynthStyle;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT;
public class 試用2 {
// 文件名字每個字母首字母大寫
// coc-convention over configuration
public static void main(String[] args) {
// 一個可以執行的MAIN方法一定要寫MAIN方法,它有自變量沒有因變量所以寫的是void
System.out.println("您的總資產為:Y"+money+"元");
int bet;
do{
System.out.println("請下注:");
int a = (int) (Math.random() * 6 + 1);
// (int) (Math.random()*6+1)
// 后面的1表示下線6表示上線減下線,
// (int) (Math.random()*6+1);
int b = (int) (Math.random() * 6 + 1);
int p = a + b;
int money = 1000;
do{
// 假如在這里之內1000還有救可以繼續循環
System.out.println("玩家搖出來" + p + "點");
boolean w = false;
switch (p) {
case 7:
case 11:
System.out.println("玩家勝利");
break;
case 2:
case 3:
case 12:
break;
default:
// 或者
w = true;
// 如果游戲沒有分出勝負,所以設置了w=true;boolean w = false
while (w) {
int a1 = (int) (Math.random() * 6 + 1);
int b1 = (int) (Math.random() * 6 + 1);
int p1= a1 + b1;
System.out.println("玩家搖出來" + p1 + "點");
if (c==7) {
System.out.println("莊家勝利!");
w = true;
while(money>0);
System.out.println("您破產了!");
}
}
}
}
}
package UTF8;
public class C1游戲 {
public static void main(String[] args) {
附源碼:
/*craps 雙骰兒賭博*/
/*天上人間9月28日*/
/*游戲規則:玩家擲兩骰子,骰子停下來后,計算兩個骰子向上面的點數之各。
* 如果第一次擲的和是7或11,玩家贏;
* 如果和為2,3或12(稱為craps)則玩家輸,莊家贏。
* 如果和為4,5,6,8,9或10則,這個和就成為玩家的點數,繼續擲骰子
* 此時如果擲的點數和等于點數,則玩家贏,如等于7,剛玩家輸,
* 否則,再擲骰子直至分出輸贏*/
package craps;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Date;
public class craps extends JApplet implements ActionListener{
//初始變量
final int WON=1,FAIL=0,CONTINUE=2;
boolean firstRoll=true;//標記是否是第一盤
int sum=0,mypoint=0;
int getStatus=CONTINUE;//初始化玩家狀態
JLabel dic1lbl,dic2lbl,sumlbl,pointlbl;
JTextField dic1fld,dic2fld,sumfld,pointfld;
JButton rollbt;
public void init()
{
//初始化容器
Container contain=this.getContentPane();
contain.setLayout(new FlowLayout());
dic1lbl=new JLabel("dice1");
contain.add(dic1lbl);
dic1fld=new JTextField(10);
dic1fld.setEditable(false);
contain.add(dic1fld);
dic2lbl=new JLabel("dice2");
contain.add(dic2lbl);
dic2fld=new JTextField(10);
dic2fld.setEditable(false);
contain.add(dic2fld);
sumlbl=new JLabel("sum");
contain.add(sumlbl);
sumfld=new JTextField(10);
sumfld.setEditable(false);
contain.add(sumfld);
pointlbl=new JLabel("point");
contain.add(pointlbl);
pointfld=new JTextField(10);
pointfld.setEditable(false);
contain.add(pointfld);
rollbt=new JButton("Roll Dice");
rollbt.addActionListener(this);
contain.add(rollbt);
Date date=new Date();
JLabel datelbl=new JLabel(date.toString());
contain.add(datelbl);
}
//處理事件
public void actionPerformed(ActionEvent actionEvent)
{
if(firstRoll)
//玩家第一玩
{
sum=rolldice();
switch(sum)
{
case 7:
case 11:
// sumfld.setText(sum);
pointfld.setText(" ");
getStatus=WON;
break;
case 2:
case 3:
case 12:
pointfld.setText(" ");
getStatus=FAIL;
break;
default:
mypoint=sum;
pointfld.setText(Integer.toString(mypoint));
getStatus=CONTINUE;
firstRoll=false;
break;
}
}
else //玩家繼續
{
sum=rolldice();
if(sum == mypoint)
getStatus=WON;
else
if(sum==7)
getStatus=FAIL;
}
information();
}
//擲兩次骰子的模塊
public int rolldice()
{
int dice1,dice2,sum1;
dice1=1+(int)(Math.random()*6);
dice2=1+(int)(Math.random()*6);
sum1=dice1+dice2;
dic1fld.setText(Integer.toString(dice1));
dic2fld.setText(Integer.toString(dice2));
sumfld.setText(Integer.toString(sum1));
return sum1;
}
//狀態欄提示信息
public void information()
{
if(getStatus==CONTINUE)
showStatus("玩家沒輸了沒贏,請繼續");
else{
if(getStatus==WON)
showStatus("恭喜你:玩家贏了!再玩一盤.....");
else
showStatus("玩家輸了!再試一次.....");
firstRoll=true;//設置狀態變量
}
}
}
import java.util.Scanner;
public class GongYueShu {
public static void main(String[] args) {
// TODO Auto-generated method stub
//調用java.util.Scanner可以獲得從鍵盤輸入的數字;
Scanner s = new Scanner(System.in);
//定義兩個整型數字的變量
int min;
int max;
System.out.print("請輸入一個數:");
min= s.nextInt();//nextInt();方法用來獲取輸入的Inc NUM
System.out.print("請輸入另一個數:");
max= s.nextInt();
//調用后面的靜態方法;
System.out.println(gongyue(min, max));
System.out.println(gongbei(min, max));
}
// a與b的最大公約數
public static int gongyue(int min, int max) {
while(max%min!=0){
// /運用遞歸調用將求余之后的值作為min
// * 將之前的min作為max直到求余值為0為止結束循環/
int temp=max%min;
max=min;
min=temp;
}
return min;
}
// a與b的最小公倍數
public static int gongbei(int min, int max) {
//求公倍數就是將兩個數相乘除以最大公約數
return min max / gongyue(min, max);
}
}
package UTF8;
public class qq2 {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
//
System.out.println(i+"eeeee");
}
System.out.println("jieshu");
}
}
package UTF8;
import java.util.Scanner;
// 和計算機猜數字
public class Caiziyouxi1 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
// 設置的值是S。所以記得結束的時候也用s.close();
int answer = (int) (Math.random() * 100 + 1);
int you;
do {
System.out.println("請輸入你猜的數字:");
you = s.nextInt();
} while (you != answer);
s.close();
// 設置的值是S。所以記得結束的時候也用s.close();
}
}
package UTF8;
import java.util.Scanner;
public class Saizi {
// 1.把一顆塞子搖6萬次,統計每一面出現的次數
// 2.找出100~999之間的水仙花數(153 = 1^3次方)=153 = 111+555+333
// 3.輸入兩個整數,求最大公約數和最小公倍數
public static void main(String[] args) {
// 先寫出MAIN公式
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
// 掃描儀
System.out.print("請輸入次數:");
// 系統打印器
int count = s.nextInt();
int result[] = new int[6];
// 給它設未知數count和result
int index = 0;
//
for (int i = 0; i < count; i++) {
//
index = (int) ((Math.random() * 6));
//
result[index] = result[index] + 1;
}
//
for (int j = 0; j < result.length; j++) {
//
System.out.println(j + 1 + "出現的次數為:" + result[j]);
}
}
}
package UTF8;
public class C1游戲 {
public static void main(String[] args) {
附源碼:
/*craps 雙骰兒賭博*/
/*天上人間9月28日*/
/*游戲規則:玩家擲兩骰子,骰子停下來后,計算兩個骰子向上面的點數之各。
* 如果第一次擲的和是7或11,玩家贏;
* 如果和為2,3或12(稱為craps)則玩家輸,莊家贏。
* 如果和為4,5,6,8,9或10則,這個和就成為玩家的點數,繼續擲骰子
* 此時如果擲的點數和等于點數,則玩家贏,如等于7,剛玩家輸,
* 否則,再擲骰子直至分出輸贏*/
package craps;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Date;
public class craps extends JApplet implements ActionListener{
//初始變量
final int WON=1,FAIL=0,CONTINUE=2;
boolean firstRoll=true;//標記是否是第一盤
int sum=0,mypoint=0;
int getStatus=CONTINUE;//初始化玩家狀態
JLabel dic1lbl,dic2lbl,sumlbl,pointlbl;
JTextField dic1fld,dic2fld,sumfld,pointfld;
JButton rollbt;
public void init()
{
//初始化容器
Container contain=this.getContentPane();
contain.setLayout(new FlowLayout());
dic1lbl=new JLabel("dice1");
contain.add(dic1lbl);
dic1fld=new JTextField(10);
dic1fld.setEditable(false);
contain.add(dic1fld);
dic2lbl=new JLabel("dice2");
contain.add(dic2lbl);
dic2fld=new JTextField(10);
dic2fld.setEditable(false);
contain.add(dic2fld);
sumlbl=new JLabel("sum");
contain.add(sumlbl);
sumfld=new JTextField(10);
sumfld.setEditable(false);
contain.add(sumfld);
pointlbl=new JLabel("point");
contain.add(pointlbl);
pointfld=new JTextField(10);
pointfld.setEditable(false);
contain.add(pointfld);
rollbt=new JButton("Roll Dice");
rollbt.addActionListener(this);
contain.add(rollbt);
Date date=new Date();
JLabel datelbl=new JLabel(date.toString());
contain.add(datelbl);
}
//處理事件
public void actionPerformed(ActionEvent actionEvent)
{
if(firstRoll)
//玩家第一玩
{
sum=rolldice();
switch(sum)
{
case 7:
case 11:
// sumfld.setText(sum);
pointfld.setText(" ");
getStatus=WON;
break;
case 2:
case 3:
case 12:
pointfld.setText(" ");
getStatus=FAIL;
break;
default:
mypoint=sum;
pointfld.setText(Integer.toString(mypoint));
getStatus=CONTINUE;
firstRoll=false;
break;
}
}
else //玩家繼續
{
sum=rolldice();
if(sum == mypoint)
getStatus=WON;
else
if(sum==7)
getStatus=FAIL;
}
information();
}
//擲兩次骰子的模塊
public int rolldice()
{
int dice1,dice2,sum1;
dice1=1+(int)(Math.random()*6);
dice2=1+(int)(Math.random()*6);
sum1=dice1+dice2;
dic1fld.setText(Integer.toString(dice1));
dic2fld.setText(Integer.toString(dice2));
sumfld.setText(Integer.toString(sum1));
return sum1;
}
//狀態欄提示信息
public void information()
{
if(getStatus==CONTINUE)
showStatus("玩家沒輸了沒贏,請繼續");
else{
if(getStatus==WON)
showStatus("恭喜你:玩家贏了!再玩一盤.....");
else
showStatus("玩家輸了!再試一次.....");
firstRoll=true;//設置狀態變量
}
}
}
package UTF8;
import java.util.Scanner;
public class Caiziyouxi {
private static final String co = null;
private static Scanner s;
public static void main(String[] args) {
System.out.println("歡迎你試玩猜數字游戲:");
System.out.println("請安1開始2退出");
Scanner s = new Scanner(System.in);
int a = s.nextInt();
if (a == 1) {
System.out.println("---------");
Scanner cScanner = new Scanner(System.in);
int max = 0;
int j = 0;
int i = 0;
max = (int) (Math.random() * 100);
do {
System.out.println("請您輸入數字:");
j = s.nextInt();
if (j < max) {
System.out.println("太小了哦");
}
if (j > max) {
System.out.println("太大了哦");
}
if (j == max) {
break;
}
i++;
} while (i < 10);
switch (i) {
case 1:
System.out.println("您猜對了,你是神仙?");
break;
case 2:
System.out.println("您猜對了,厲害了我的哥");
break;
case 3:
System.out.println("您猜對了,厲害了我的哥");
break;
case 4:
System.out.println("您猜對了,厲害了我的哥");
break;
case 5:
System.out.println("您猜對了,厲害了我的哥");
break;
case 6:
System.out.println("您猜對了,厲害了我的哥");
break;
case 7:
System.out.println("您猜對了,一般一般");
break;
case 8:
System.out.println("您猜對了,智商啊");
break;
case 9:
System.out.println("您猜對了,智商呵呵");
break;
case 10:
System.out.println("您猜對了,回爐改造吧");
break;
default:
System.out.println("對不起你沒猜對");
break;
}
cScanner.close();
}
System.out.println("謝謝您的使用");
s.close();
}
}
package UTF8;
public class ShuiXianHua {
// 水仙花數是指:一個三位數,其各位數字的立方和等于該數本身
// 例如:153就是一個水仙花數。
// 153 = 111 + 555 + 333 = 1 + 125 + 27 = 153
public static void main(String[] args) {
int count = 0;
for (int i = 100; i < 999; i++){
// 或for (int i = 100; i < 999; i+=1)
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 100 % 10;
if (i == ge * ge * ge + shi * shi * shi + bai * bai * bai) {
System.out.println(i + "是水仙花數");
count++;
}
}
System.out.println("一共有" + count + "個水仙花數");
}
}
package UTF8;
import java.util.Scanner;
public class Xunhuan {
public static void main(String[] args) {
int i = 0;
// 累加要從0開始乘,累減要從1開始。
do {
System.out.println(i + "aaaaa");
i += 1;
} while (i < 10);
System.out.println("程序結束循環");
}
}
package wyy;
import java.util.Scanner;
public class yuandebanjing {
public static void mian(string[]args){
Scanner input=new Scanner(System.in);
//SYStem.in表示
final double PI=3.1416;
//被final修飾的變量只能一次賦值以后不能再修改它的值
//通常稱之為常量
System.out.print("請輸入園的半徑");
double radius=input.nextDouble();
System.out.println("周長":+(2*PI*radius));
System.out.println("面積":PI*radius*radius);
input.close();
}
}
package wyy;
import java.util.Scanner;
public class yingcun {
// class=淚的文件夾名字取名叫
public static void main(String[] args) {
// 開始輸出這個的背。不過以后記住main按ALN.+/回車就好了
// 注釋:程序中起說明作用的文字,不參與編譯,更不能影響代碼的執行結果
System.out.print("請輸入一個英寸值:");
// System=系統out=外面的print打印
// 設置X英寸值,方便別人輸入查詢
Scanner input = new Scanner(System.in);
// 創建一個掃描器。SYSTEM.IN=標準輸入,鍵盤輸入數字就好
double cm=input.nextDouble();
// double可保持整數或小數點數字。
// 或者用int cm=....等int單位表示CM轉換=多少或者什么單位的意思
input.close();
// 表示結束輸出
System.out.printf("%.2f英寸=%.2f厘米\n", cm,cm* 2.54);
// print加IN等于換行,不加IN等于不換行,如print
// 這里是表示怎么算,公式是什么
// 00000000
// 00000001
// 10000010
// 11111111 反碼
}
}
package wyy;
import javax.naming.directory.ModificationItem;
public class Yaoshaizi {
public static void main(String[] args) {
int face = (int) (Math.random() * 6 + 1);
System.out.println("搖出了" + face + "點哦");
String punishment = "";
// 表示給punishment賦值,讓計算機知道里面有多少,“”表示X不知道多少但是有值就可以使用
switch (face) {
case 1:
punishment = "跳舞0-0";
break;
case 2:
punishment = "親吻你左邊的人!";
break;
case 3:
punishment = "唱首歌!";
break;
case 4:
punishment = "喝一杯!";
break;
case 5:
punishment = "大冒險!";
break;
case 6:
punishment = "真心話!";
break;
}
System.out.println("懲罰是:" + punishment);
}
}
package wyy;
import java.util.Scanner;
public class TestDay{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請選擇性別,男性按0,女性按1:");
// 提示
double xb = input.nextDouble();
if (xb == 1) {
System.out.println("請輸入您的身高:");
double shengao = input.nextDouble();
// 提示和命名
System.out.println("請輸入您的體重:");
double tizhong = input.nextDouble();
if (shengao - 100 >= tizhong) {
System.out.println("您的身體不健康");
} else {
System.out.println("您的身體健康");
}
} else if (xb == 0) {
System.out.println("請輸入您的身高:");
double shengao = input.nextDouble();
System.out.println("請輸入您的體重:");
double tizhong = input.nextDouble();
if (shengao - 80 >= tizhong) {
System.out.println("您的身體不健康");
} else {
System.out.println("您的身體健康");
}
} else {
System.out.println("別鬧,乖乖選擇0或1.");
}
input.close();
}
}
// string后面跟名字就變成了表示名字的字符名稱
// int。refvalue = NAN
// 如:string shengao =input.next();
// 或者 =input.nextline();
// 建議使用input.nextline();
// 因為按空格等你還沒輸入完就已經讀取走了,
// bug-臭屁蟲
// debug-調試/抓蟲的意思
// 程序有問題以后點害蟲,進行斷點標記調試。
package wyy;
import wyy.Shou.SZTax;
public class Shui {
public class Shou {
public class SZTax {
/**
* 返回扣除社保醫保公積金后薪水
* @param salaryBeforeTax 扣除社保醫保公積金前薪水
* @return
*/
public int salaryAfterTax(int salaryBeforeTax)
{
// (3W-3.5K)25%-1005
// 扣稅公式是:
// (扣除社保醫保公積金后薪水-個稅起征點)稅率-速算扣除數
System.out.println("請輸入您的工資");
int taxbase=salaryBeforeTax-3500;
int Taxrate=0;//這里稅率沒有除以百分比;
int Quickdeduction=0;
if(taxbase <=0)//低于個稅起征點
{
return salaryBeforeTax;
}else if(taxbase <=1500)
{
Taxrate=3;
Quickdeduction=0;
}else if(taxbase <=4500)
{
Taxrate=10;
Quickdeduction=105;
}else if(taxbase <=9000)
{
Taxrate=20;
Quickdeduction=555;
}else if(taxbase <=35000)
{
Taxrate=25;
Quickdeduction=1005;
}else if(taxbase <=55000)
{
Taxrate=30;
Quickdeduction=2755;
}else if(taxbase <=80000)
{
Taxrate=35;
Quickdeduction=5505;
}else
{
Taxrate=45;
Quickdeduction=13505;
}
return salaryBeforeTax-((salaryBeforeTax-3500)*Taxrate/100-Quickdeduction);
}
public void costeffectivesalary(int salaryBeforeTax)
{
//從1萬算起,100的步長算到10萬,找出稅后稅前比最大的。
for (;salaryBeforeTax <= 100000; salaryBeforeTax=salaryBeforeTax+100) {
float rate=(float)salaryAfterTax(salaryBeforeTax)/salaryBeforeTax*100000;
System.out.println(""+salaryBeforeTax+"-----------"+salaryAfterTax(salaryBeforeTax)+"-----------"+rate);
}
}
public void main(String[] args)
{
new SZTax().costeffectivesalary(10000);
}
}}
}
package wyy;
import java.util.Scanner;
public class SanJiaoXing {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
input.close();
//boolean isvalid =(a+b>c&&b+c>a&&a+c>b)
// if (isvalid)
if (a+b>c&&b+c>a&&a+c>b){
double perimetar = a+b+c;
double half = perimetar/2;
double area = Math.sqrt
(half(half-a)(half-b)*(half-c));
System.out.printf("zhouchang:%.2f\n", perimetar);
System.out.printf("mianji:%.2f\n", area);
}
else{
System.out.println("不能構成三角型");
}
}
}
package wyy;
import java.util.Scanner;
public class NianFen {
private static boolean isLeapYear(int year) {
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入年和月: ");
int year = input.nextInt();
/* @year year 表示每年
*/
int month = input.nextInt();
// 表示月份
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println("31天");
break;
case 2:
if (isLeapYear(year)) {
System.out.println("是閏年29天");
}
else {
System.out.println("不是閏年28天");
}
break;
case 4:
case 6:
case 9:
case 11:
System.out.println("30天");
break;
default:
System.err.println("輸出錯誤");
// 用ERR不是用out的話顯示錯誤會變成紅色的字,更醒目
}
input.close();
}
// 或者這樣寫。
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入您的月份");
if(year>0&&month>=1&&month<=12){
int days;
if(month == 2){
days =(year%4 == 0 && year % 100 ! = 0)
}
}
}
}
package wyy;
import java.util.Scanner;
public class JiQiRen {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請輸入");
String yourQuestion = input.nextLine();
String answer;
switch(yourQuestion){
case "你好":
answer = "你也好呀!";
break;
case "你叫什么名字":
case "你的名字":
case "你的姓名":
answer = "我呀,叫王瑤瑤的小棉襖!";
break;
case "操你大爺":
case "草泥馬":
case "MDZZ":
case "我是你爸":
answer = "人家還小,請使用文明用語(┸)!";
break;
case "滾蛋":
case "爬":
case "你走開":
answer = "我走了,誰陪你聊天呢?";
break;
case "你多大了":
answer = "年齡是女孩子們的秘密哦!";
break;
}
input.close();
}
}package wyy;
import java.util.Scanner;
public class JianKang {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.println("請輸入您的身高:");
double high=input.nextDouble();
System.out.println("請輸入您的體重:");
double weight=input.nextDouble();
System.out .println("如果你是女生請輸入1,如果你是男生請輸入0。");
double sex=input.nextDouble();
if(sex==1){
if (high-100>=weight) {
System.out.println("您的身體情況為健康。");
}
else{
System.out.println("您的身體情況不健康。");
}
}
else{
if(high-80>=weight){
System.out.println("您的身體情況為健康。");
}
else{
System.out.println("您的身體情況不健康。");
}
}
}
}
package wyy;
import java.awt.ItemSelectable;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
//public表示私有或者公有
Scanner input=new Scanner(System.in);
System.out.print("a=");
double a=input.nextDouble();
System.out.print("b=");
double b=input.nextDouble();
//(system.in)=輸入
//變量;
//這個符號表示標記,不做運算,只是讓自己好看懂
//變量-數據的存儲空間
//定義變量的語法:
//類型 變量名=值
input.close();
// f - printf = 格式化
//%f\n \n表示換行
//%.2f\n .2表示保留小數點后2位,如果是%。0就是不保留后面的小數點
System.out.printf("%f+%f=%.0f\n",a,b,a+b);
System.out.printf("%f-%f=%.2f\n",a,b,a-b);
//%.2f\n .2表示保留小數點后2位,如果是%。0就是不保留后面的小數點
System.out.println("a*b="+(a*b));
System.out.printf("%f/%f=%.0f\n",a,b,a/b);
//樓下是求百分比
System.out.printf("%f %% %f=%.0f\n",a,b,a%b);
//說明:如果要在格式化字符串中寫%
//那么需要寫成%%兩個%分號(第一個%是轉義字符)
System.out.printf("%f-%f=%.2f\n",a,b,a-b);
}
}
package wyy;
public class Fuhao {
public static void mian(String[] args) {
int a = 5;
int b = ++a + a;
// ++把自身加1.
// --把自身加1.如a--表示5+1 = 6.
// --a表示a本身 = 5.
// 強制性運算:
// double x = 3.9999
// int a = (int)x;
// 表示強制性轉換為整數,舍棄小數點后 的數字,
// 表示只要3.。。。。。后面的999舍棄掉
// 所以以后要這樣做的時候前面加個(int)
// short d=100;
// d+ = 1;這樣就自帶強轉型了。
// 所以別d = d+1.直接使用d+1 = 1;
// 位運算:
// int a = 3;
// system.out.println(a<<3);
// 表示3乘以3的3次方,向左移動3次.24向左移動8米3次為24
// 只能左右移動32.如果移動33就是一個比特的位次了回到了移動1的含義
// 快捷鍵;整理:ctrl+shift+f
//幫你補充還沒打出來的字:ctrl+shift=o
//
}
}