import java.util.Scanner;
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信平臺小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了梁園免費(fèi)建站歡迎大家使用!
public class test {
public static void main(String[] args) {
int a=1;
while(a!=0)
{
Scanner input = new Scanner(System.in);
System.out.println("輸入整數(shù)(輸入0結(jié)束)");
a = input.nextInt();
if(a0a1000)
{
int b = a % 10;
int temp = a / 10;
int c = temp % 10;
int d = temp/10;
int result = b + c + d;
System.out.println("該整數(shù)的各位相加是"+result);
}else
{
System.out.println("該整數(shù)不再0和1000之間");
}
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*; //引入所需要的包
class MyFrame extends JFrame implements ActionListener{
private JButton b1,b2,b3,b4,b5,b6;
private TextField t1,t2,t3; //定義六個(gè)按鈕和三個(gè)文本域
public MyFrame(String s){
super(s);
b1=new JButton("加");
b2=new JButton("減");
b3=new JButton("乘");
b4=new JButton("除");
//對按鈕加文字標(biāo)簽
Panel p=new Panel(); //生成一個(gè)面板
p.setLayout(new FlowLayout()); //以FlowLayout來規(guī)劃面板中的組件
t1=new TextField ("",4);
t2=new TextField("",4);
t3=new TextField("",4); //生成文本域并設(shè)置長度
p.add(new JLabel("Num1"));p.add(t1);
p.add(new JLabel("Num2"));p.add(t2);
p.add(new JLabel("Res"));p.add(t3);//順次在面板中加入按鈕和文本域
t3.setEditable(false); //設(shè)置t3不可編輯
Panel button=new Panel();
button.setLayout(new GridLayout(2,2));//以兩行2列來布局button面板中的各組件
button.add(b1);button.add(b2);button.add(b3);
button.add(b4);
getContentPane().add(button,BorderLayout.SOUTH);
getContentPane().add(p,BorderLayout.NORTH);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
//注冊事件監(jiān)聽器
}
public void actionPerformed(ActionEvent e){ //實(shí)現(xiàn)接口方法
double number1=Double.parseDouble(t1.getText());
double number2=Double.parseDouble(t2.getText());//得到文本域中的數(shù)字字符串調(diào)用parseDouble()函數(shù)轉(zhuǎn)化為數(shù)值型數(shù)字
if(e.getSource()==b1)
{
double result=number1+number2;
t3.setText(String.valueOf(result));//實(shí)現(xiàn)+
}
if(e.getSource()==b2)
{
double result=number1-number2;
t3.setText(String.valueOf(result));//實(shí)現(xiàn)-
}
if(e.getSource()==b3)
{
double result=number1*number2; //實(shí)現(xiàn)*
t3.setText(String.valueOf(result));
}
if(e.getSource()==b4) //實(shí)現(xiàn)/
{
double result=number1/number2;
t3.setText(String.valueOf(result));
}
}
}
public class Calculator{
public static void main(String[] args){
MyFrame frm=new MyFrame("Welcome to my calculator"); //設(shè)置標(biāo)題
frm.setSize(320,240); //設(shè)置大小
frm. setVisible(true);//可見
}
}
樓主湊合用
public class admin {
String name;
int i = 1;
int mima;
Scanner in = new Scanner(System.in);
public void show() {
for (int i = 2; i = 0; i--) {
System.out.print("請輸入用戶名:");
name = in.next();
System.out.print("請輸入密碼:");
mima = in.nextInt();
if (name.equals("admin1") mima == 111111) {
System.out.print("\n請輸入新密碼:");
mima = in.nextInt();
System.out.println("修改密碼成功,您的新密碼為:" + mima);
break;
} else {
if (i != 0) {
System.out.println("用戶名和密碼不匹配!請重新輸入(您還有)" + i + "次機(jī)會");
break;
} else {
System.out.println("用戶名和密碼不匹配!您沒有權(quán)限更新用戶信息。");
break;
}
}
}
}
}
當(dāng)前題目:java縮減代碼 java如何降低代碼重復(fù)率
網(wǎng)址分享:http://jinyejixie.com/article46/dopcjhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、小程序開發(fā)、云服務(wù)器、網(wǎng)站制作、網(wǎng)站營銷、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)