#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int a,b,c;
int main(){
printf("請輸入三邊的長,並以逗號隔開:\n");
scanf("%d,%d,%d",&a,&b,&c);
if(a<=0 || b<=0 || c<=0){
printf("請輸入正數");
return 1;
}
if(a+b>c && b+c>a && c+a>b){
if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==b*b+a*a){
printf("是直角三角形\n");
return 0;
}
if(a==b||b==c||a==c){
if(a==b && b==c && a==c){
printf("是正三角形\n");
return 0;
}
else if(a==b!=c || b==c!=a || c==a!=b){
printf("是等腰三角形\n");
return 0;
}
}
printf("other三角形\n");
return 0;
}
else if(a+b<=c || b+c<=a || c+a<=b){
printf("No 三角形\n");
return 0;
}
}
HELLO~JAVA
關於我
就讀逢甲大學
正在修java
2016年10月30日 星期日
2015年5月27日 星期三
2015年5月26日 星期二
期末考試 APP Inventor 2 範例程式 比大小遊戲 20分
1.製作的網頁
(1) 電腦為莊家,使用者為玩家
(2) 每回合下賭注,每人兩顆骰子
(3) 點數合比大小,大者勝出,平手則為莊家贏
3.畫面配置:
4.程式碼
5.手機畫面
2015年5月16日 星期六
期末考試40分利用Android Studio 寫APP範例 BMI程式
1. 安裝Android Studio
到此網站http://developer.android.com/sdk/installing/studio.html
下載Android Studio並安裝
2.照他的方法一步一步做
http://chiachiku.pixnet.net/blog/post/64235911-android%E7%A8%8B%E5%BC%8F%E7%AF%84%E4%BE%8B%EF%BC%88%E4%B8%80%EF%BC%89bmi%E8%A8%88%E7%AE%97%E7%A8%8B%E5%BC%8F---%E8%A4%87%E8%A3%BD%E7%AF%87
3.完成圖
到此網站http://developer.android.com/sdk/installing/studio.html
下載Android Studio並安裝
2.照他的方法一步一步做
http://chiachiku.pixnet.net/blog/post/64235911-android%E7%A8%8B%E5%BC%8F%E7%AF%84%E4%BE%8B%EF%BC%88%E4%B8%80%EF%BC%89bmi%E8%A8%88%E7%AE%97%E7%A8%8B%E5%BC%8F---%E8%A4%87%E8%A3%BD%E7%AF%87
3.完成圖
2015年5月15日 星期五
圖片推盤
1.先利用IG或其他的將圖片改成1:1的大小
2.http://rs5257.pixnet.net/blog/post/24358691-%E7%B7%9A%E4%B8%8A%E5%9C%96%E7%89%87%E5%88%87%E5%89%B2%E8%88%87%E5%89%AA%E8%A3%81
在利用上述網址教學把圖片才成16份
3.記得看圖片大小是幾成幾
EX:640*640的圖片大小切成16份就是等於每個1/16的圖片大小是160*160
4.然後再去改每個圖片的大小改成90*90
5.圖檔要用.png
6.圖檔請放在你放java檔的資料夾裡
7.圖檔名請用1,2,3.........以此類推 切割前的圖片不用改檔名沒關係
8.程式碼如下
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
class J_JPanel extends JPanel
{
/**
*
*/
private static final long serialVersionUID = 1L;
Image m_image;
int showpicture=0;
@SuppressWarnings("static-access")
public J_JPanel()throws IOException
{ J_Puzzle a = new J_Puzzle();
if(a.changetime==-1)
showpicture = 1;
File f = new File("11111.png");
m_image = ImageIO.read(f);
}
public void paintComponent(Graphics g)
{
g.drawImage(m_image, 0, 0, 700, 700, this);
}
}
public class J_Puzzle extends JFrame implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
int i,j;
static int changetime = 0;
Container c = getContentPane();
JButton b[] = new JButton[16];
ImageIcon ic[][] = new ImageIcon[2][15];
public J_Puzzle() throws IOException
{
super("拼圖小遊戲");
String pic_name[] = new String[15];
for(i = 0;i < 2;i ++)
for(j = 0;j < 15;j ++)
{
pic_name[j] = String.valueOf(j+1+i*15)+".png";
ic[i][j] = new ImageIcon(pic_name[j]);
}
JMenuBar mBar = new JMenuBar();
setJMenuBar(mBar);
int k = 0;
JMenu []m = {new JMenu("菜單(M)"),new JMenu("幫助(H)")};
char mC[][] = {{'M','H'},{'S','X','C','Z'},{'E','T'}};
JMenuItem mItem[][] = {{new JMenuItem("開始(S)"),new JMenuItem("重置(X)"),new JMenuItem("背景更換(C)"),new JMenuItem("退出(Z)")},{new JMenuItem("查看樣圖(E)"),new JMenuItem("關於(T)")}};
for(i = 0;i < 2;i ++)
{
mBar.add(m[i]);
m[i].setMnemonic(mC[0][i]);
if(i==0)k = 0;
else k = 1;
for(j = 0;j < 4-i-k;j ++)
{
m[i].add(mItem[i][j]);
mItem[i][j].setMnemonic(mC[i+1][j]);
mItem[i][j].setAccelerator(KeyStroke.getKeyStroke("ctrl"+mC[i+1][j]));
mItem[i][j].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
JMenuItem mItem = (JMenuItem)e.getSource();
if(mItem.getText().equalsIgnoreCase("重置(X)")||mItem.getText().equalsIgnoreCase("開始(S)"))
{
int location[][] = {{17,13},{17,103},{17,193},{17,283},{107,13},{107,103},{107,193},{107,283}
,{197,13},{197,103},{197,193},{197,283},{287,13},{287,103},{287,193},{287,283}};
int rd_number[] = new int[16];
rd_number = randomnumber();
for(i = 1;i < 16;i ++)
b[i].setLocation(location[rd_number[i-1]-1][0],location[rd_number[i-1]-1][1]);
}
else if(mItem.getText().equalsIgnoreCase("背景更換(C)"))
{
changetime++;
for(i = 0;i < 15;i ++)
{
b[i+1].setIcon(null);
b[i+1].setIcon(ic[changetime][i]);
}
if(changetime==1)
changetime = -1;
}
else if(mItem.getText().equalsIgnoreCase("退出(Z)"))
{
int a = JOptionPane.showConfirmDialog(null, "您確定退出遊戲?");
if(a==0)
System.exit(0);
}
else if(mItem.getText().equalsIgnoreCase("查看樣圖(E)"))
{
JFrame jj = new JFrame("樣圖");
jj.setSize(700, 700);
jj.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/3-700,
Toolkit.getDefaultToolkit().getScreenSize().height/4);
jj.setVisible(true);
Container c1 = jj.getContentPane();
try {
c1.add(new J_JPanel(),BorderLayout.CENTER);
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(mItem.getText().equalsIgnoreCase("關於(T)"))
{
JOptionPane.showMessageDialog(null, "簡單小遊戲\n製作人:菜鳥");
}
}
});
}
}
m[0].insertSeparator(1);m[1].insertSeparator(1);
GridBagLayout gr = new GridBagLayout();
c.setLayout(gr);
int gx[] = {0,1,2,3};
int gy[] = {0,1,2,3};
int k1;
Dimension d = new Dimension(90,90);
String s_number;
GridBagConstraints gc = new GridBagConstraints();
for(i = 1;i < 5;i ++)
{
if(i==4)k1=4;
else k1=5;
for(j = 1;j < k1;j ++)
{
gc.gridx = gx[j-1];
gc.gridy = gy[i-1];
gc.fill = GridBagConstraints.NONE;
s_number = String.valueOf(j+(i-1)*4);
b[j+(i-1)*4] = new JButton(s_number,ic[0][j+(i-1)*4-1]);
b[j+(i-1)*4].setPreferredSize(d);
b[j+(i-1)*4].setFont(new Font("宋體",Font.PLAIN,0));
gr.setConstraints(b[j+(i-1)*4],gc);
c.add(b[j+(i-1)*4]);
}
}
for(i = 1;i <16;i ++)
b[i].addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int j;
JButton b = (JButton)e.getSource();
Point p = b.getLocation();
Point p1 = null;
for(j = -1;j < 2;j ++)
{
if(p.y+j*90>283||p.y+j*90<13)
continue;
else
{
Component a = c.getComponentAt(p.x, p.y+j*90);
if(a.getHeight()!=90)
p1 = new Point(p.x,p.y+j*90);
}
}
for(j = -1;j < 2;j ++)
{
if(p.x+j*90>287||p.x+j*90<17)
continue;
else
{
Component a = c.getComponentAt(p.x+j*90, p.y);
if(a.getHeight()!=90)
p1 = new Point(p.x+j*90,p.y);
}
}
if(p1!=null)
b.setLocation(p1.x, p1.y);
if(check()==true)
JOptionPane.showMessageDialog(null, "恭喜您成功了");
}
/*?生?机?*/
public int[] randomnumber()
{
Random rd = new Random();
int n[] = new int[15];
for(int i = 0 ;i < 15;i ++)
{
int temp = rd.nextInt(15)+1;
n[i] = temp;
for(int j = 0;j < i;j ++)
if(n[j]==temp)
{
i--;
break;
}
}
return n;
}
/*判?是否排序成功*/
public boolean check()
{
Point location[] = new Point[16];
boolean bo = false;
int count=0;
for(int i = 0;i < 4;i ++)
for(int j = 0;j < 4;j ++)
location[i*4+j] = new Point(17+j*90, 13+i*90);
for(int i = 0;i < 15;i ++)
{
if(b[i+1].getLocation().x==location[i].x&&b[i+1].getLocation().y==location[i].y)
count++;
if(count==15)
bo=true;
}
return bo;
}
public static void main(String args[]) throws IOException
{
J_Puzzle app = new J_Puzzle();
app.setDefaultCloseOperation(EXIT_ON_CLOSE);
app.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/3, Toolkit.getDefaultToolkit().getScreenSize().height/4);
app.setSize(700,700);
app.setVisible(true);
app.setResizable(false);
}
}
9.完成圖
2.http://rs5257.pixnet.net/blog/post/24358691-%E7%B7%9A%E4%B8%8A%E5%9C%96%E7%89%87%E5%88%87%E5%89%B2%E8%88%87%E5%89%AA%E8%A3%81
在利用上述網址教學把圖片才成16份
3.記得看圖片大小是幾成幾
EX:640*640的圖片大小切成16份就是等於每個1/16的圖片大小是160*160
4.然後再去改每個圖片的大小改成90*90
5.圖檔要用.png
6.圖檔請放在你放java檔的資料夾裡
7.圖檔名請用1,2,3.........以此類推 切割前的圖片不用改檔名沒關係
8.程式碼如下
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
class J_JPanel extends JPanel
{
/**
*
*/
private static final long serialVersionUID = 1L;
Image m_image;
int showpicture=0;
@SuppressWarnings("static-access")
public J_JPanel()throws IOException
{ J_Puzzle a = new J_Puzzle();
if(a.changetime==-1)
showpicture = 1;
File f = new File("11111.png");
m_image = ImageIO.read(f);
}
public void paintComponent(Graphics g)
{
g.drawImage(m_image, 0, 0, 700, 700, this);
}
}
public class J_Puzzle extends JFrame implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
int i,j;
static int changetime = 0;
Container c = getContentPane();
JButton b[] = new JButton[16];
ImageIcon ic[][] = new ImageIcon[2][15];
public J_Puzzle() throws IOException
{
super("拼圖小遊戲");
String pic_name[] = new String[15];
for(i = 0;i < 2;i ++)
for(j = 0;j < 15;j ++)
{
pic_name[j] = String.valueOf(j+1+i*15)+".png";
ic[i][j] = new ImageIcon(pic_name[j]);
}
JMenuBar mBar = new JMenuBar();
setJMenuBar(mBar);
int k = 0;
JMenu []m = {new JMenu("菜單(M)"),new JMenu("幫助(H)")};
char mC[][] = {{'M','H'},{'S','X','C','Z'},{'E','T'}};
JMenuItem mItem[][] = {{new JMenuItem("開始(S)"),new JMenuItem("重置(X)"),new JMenuItem("背景更換(C)"),new JMenuItem("退出(Z)")},{new JMenuItem("查看樣圖(E)"),new JMenuItem("關於(T)")}};
for(i = 0;i < 2;i ++)
{
mBar.add(m[i]);
m[i].setMnemonic(mC[0][i]);
if(i==0)k = 0;
else k = 1;
for(j = 0;j < 4-i-k;j ++)
{
m[i].add(mItem[i][j]);
mItem[i][j].setMnemonic(mC[i+1][j]);
mItem[i][j].setAccelerator(KeyStroke.getKeyStroke("ctrl"+mC[i+1][j]));
mItem[i][j].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
JMenuItem mItem = (JMenuItem)e.getSource();
if(mItem.getText().equalsIgnoreCase("重置(X)")||mItem.getText().equalsIgnoreCase("開始(S)"))
{
int location[][] = {{17,13},{17,103},{17,193},{17,283},{107,13},{107,103},{107,193},{107,283}
,{197,13},{197,103},{197,193},{197,283},{287,13},{287,103},{287,193},{287,283}};
int rd_number[] = new int[16];
rd_number = randomnumber();
for(i = 1;i < 16;i ++)
b[i].setLocation(location[rd_number[i-1]-1][0],location[rd_number[i-1]-1][1]);
}
else if(mItem.getText().equalsIgnoreCase("背景更換(C)"))
{
changetime++;
for(i = 0;i < 15;i ++)
{
b[i+1].setIcon(null);
b[i+1].setIcon(ic[changetime][i]);
}
if(changetime==1)
changetime = -1;
}
else if(mItem.getText().equalsIgnoreCase("退出(Z)"))
{
int a = JOptionPane.showConfirmDialog(null, "您確定退出遊戲?");
if(a==0)
System.exit(0);
}
else if(mItem.getText().equalsIgnoreCase("查看樣圖(E)"))
{
JFrame jj = new JFrame("樣圖");
jj.setSize(700, 700);
jj.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/3-700,
Toolkit.getDefaultToolkit().getScreenSize().height/4);
jj.setVisible(true);
Container c1 = jj.getContentPane();
try {
c1.add(new J_JPanel(),BorderLayout.CENTER);
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(mItem.getText().equalsIgnoreCase("關於(T)"))
{
JOptionPane.showMessageDialog(null, "簡單小遊戲\n製作人:菜鳥");
}
}
});
}
}
m[0].insertSeparator(1);m[1].insertSeparator(1);
GridBagLayout gr = new GridBagLayout();
c.setLayout(gr);
int gx[] = {0,1,2,3};
int gy[] = {0,1,2,3};
int k1;
Dimension d = new Dimension(90,90);
String s_number;
GridBagConstraints gc = new GridBagConstraints();
for(i = 1;i < 5;i ++)
{
if(i==4)k1=4;
else k1=5;
for(j = 1;j < k1;j ++)
{
gc.gridx = gx[j-1];
gc.gridy = gy[i-1];
gc.fill = GridBagConstraints.NONE;
s_number = String.valueOf(j+(i-1)*4);
b[j+(i-1)*4] = new JButton(s_number,ic[0][j+(i-1)*4-1]);
b[j+(i-1)*4].setPreferredSize(d);
b[j+(i-1)*4].setFont(new Font("宋體",Font.PLAIN,0));
gr.setConstraints(b[j+(i-1)*4],gc);
c.add(b[j+(i-1)*4]);
}
}
for(i = 1;i <16;i ++)
b[i].addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int j;
JButton b = (JButton)e.getSource();
Point p = b.getLocation();
Point p1 = null;
for(j = -1;j < 2;j ++)
{
if(p.y+j*90>283||p.y+j*90<13)
continue;
else
{
Component a = c.getComponentAt(p.x, p.y+j*90);
if(a.getHeight()!=90)
p1 = new Point(p.x,p.y+j*90);
}
}
for(j = -1;j < 2;j ++)
{
if(p.x+j*90>287||p.x+j*90<17)
continue;
else
{
Component a = c.getComponentAt(p.x+j*90, p.y);
if(a.getHeight()!=90)
p1 = new Point(p.x+j*90,p.y);
}
}
if(p1!=null)
b.setLocation(p1.x, p1.y);
if(check()==true)
JOptionPane.showMessageDialog(null, "恭喜您成功了");
}
/*?生?机?*/
public int[] randomnumber()
{
Random rd = new Random();
int n[] = new int[15];
for(int i = 0 ;i < 15;i ++)
{
int temp = rd.nextInt(15)+1;
n[i] = temp;
for(int j = 0;j < i;j ++)
if(n[j]==temp)
{
i--;
break;
}
}
return n;
}
/*判?是否排序成功*/
public boolean check()
{
Point location[] = new Point[16];
boolean bo = false;
int count=0;
for(int i = 0;i < 4;i ++)
for(int j = 0;j < 4;j ++)
location[i*4+j] = new Point(17+j*90, 13+i*90);
for(int i = 0;i < 15;i ++)
{
if(b[i+1].getLocation().x==location[i].x&&b[i+1].getLocation().y==location[i].y)
count++;
if(count==15)
bo=true;
}
return bo;
}
public static void main(String args[]) throws IOException
{
J_Puzzle app = new J_Puzzle();
app.setDefaultCloseOperation(EXIT_ON_CLOSE);
app.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/3, Toolkit.getDefaultToolkit().getScreenSize().height/4);
app.setSize(700,700);
app.setVisible(true);
app.setResizable(false);
}
}
9.完成圖
2015年5月10日 星期日
按按鈕直接跑出亂數
1.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class QQ extends JFrame implements ActionListener
{
//static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
//static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
static JButton buttons[]=new JButton[25];//建立25個JButton
static JLabel labels[]=new JLabel [10];
public static void main(String args[])
{
QQ myfrm=new QQ();
String numbers[] =new String[25];
FlowLayout flow=new FlowLayout();
GridLayout grid12= new GridLayout(1,2);
GridLayout grid33= new GridLayout(5,5);
myfrm.setLayout(grid12);
myfrm.setSize(700,700);
JPanel p1 = new JPanel(grid33); //實作 panel 1
for (int i=0;i<25;i++)
{
numbers[i]=String.valueOf(i);
}
for (int i = 0; i < numbers.length; i++)
{
buttons[i] = new JButton(numbers[i]); // create buttons
p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
buttons[i].addActionListener(myfrm);
}
myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
JPanel p2 = new JPanel(flow); //實作 panel 2
myfrm.add(p2); // 在視窗myfrm 內加入 panel 2
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String stringValue;
int i,ran;
String numbers[] = new String[25];
String j;
for (i=0;i<25;i++)
{
numbers[i]=String.valueOf(i);
}
//上面迴圈是為了在numbers[ ] 裡面放進0~24的數字
for (i=0; i<=24;i++)
{
ran=(int)(Math.random()*(25-i)); // 產生亂數
buttons[i].setLabel(numbers[ran]); // 根據亂數,把numbers[ ] 裡面的數字 讓buttons[ ] 標題改變
//以下開始做對調
j=numbers[ran];
numbers[ran]=numbers[25-i-1];
numbers[25-i-1]=j;
}
}
}
2.完成圖
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class QQ extends JFrame implements ActionListener
{
//static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
//static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
static JTextField tbx1=new JTextField(2); // 建立1文字方塊物件
static JButton buttons[]=new JButton[25];//建立25個JButton
static JLabel labels[]=new JLabel [10];
public static void main(String args[])
{
QQ myfrm=new QQ();
String numbers[] =new String[25];
FlowLayout flow=new FlowLayout();
GridLayout grid12= new GridLayout(1,2);
GridLayout grid33= new GridLayout(5,5);
myfrm.setLayout(grid12);
myfrm.setSize(700,700);
JPanel p1 = new JPanel(grid33); //實作 panel 1
for (int i=0;i<25;i++)
{
numbers[i]=String.valueOf(i);
}
for (int i = 0; i < numbers.length; i++)
{
buttons[i] = new JButton(numbers[i]); // create buttons
p1.add(buttons[i], grid33); // 在 panel 1內加入按鈕陣列
buttons[i].addActionListener(myfrm);
}
myfrm.add(p1); // 在視窗myfrm 內加入 panel 1
JPanel p2 = new JPanel(flow); //實作 panel 2
myfrm.add(p2); // 在視窗myfrm 內加入 panel 2
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String stringValue;
int i,ran;
String numbers[] = new String[25];
String j;
for (i=0;i<25;i++)
{
numbers[i]=String.valueOf(i);
}
//上面迴圈是為了在numbers[ ] 裡面放進0~24的數字
for (i=0; i<=24;i++)
{
ran=(int)(Math.random()*(25-i)); // 產生亂數
buttons[i].setLabel(numbers[ran]); // 根據亂數,把numbers[ ] 裡面的數字 讓buttons[ ] 標題改變
//以下開始做對調
j=numbers[ran];
numbers[ran]=numbers[25-i-1];
numbers[25-i-1]=j;
}
}
}
2.完成圖
訂閱:
文章 (Atom)