java 编程题
麻烦请朋友们帮忙,一共有两个编程题前三张图片是一道题,第四张图片是一道题,我需要这两道题的源代码(达到题目的要求)由于比较紧迫,请您在今晚八点之前发给我,谢谢...
麻烦请朋友们帮忙,一共有两个编程题前三张图片是一道题,第四张图片是一道题,我需要这两道题的源代码(达到题目的要求)由于比较紧迫,请您在今晚八点之前发给我,谢谢
展开
4个回答
展开全部
少年 作业还是要自己搞啊 不然以后更惨.当然如果你以后不做这行无所谓了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这两道题并不难,有这时间你自己都琢磨出怎么写了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一看就是作业.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class JSimpleComputer extends JFrame implements ActionListener
{
private JTextField text1;
private JTextField text2;
private JTextField text3;
private JComboBox cb;
private JButton b;
public JSimpleComputer(){
text1 = new JTextField();
text2 = new JTextField();
text3 = new JTextField();
Vector<String> vector = new Vector<String>();
vector.add("+");
vector.add("-");
vector.add("*");
vector.add("/");
cb = new JComboBox(vector);
b = new JButton("=");
b.addActionListener(this);
Dimension preferredSize = new Dimension(50,30);
text1.setPreferredSize(preferredSize);
text2.setPreferredSize(preferredSize);
text3.setPreferredSize(preferredSize);
this.add(text1);
this.add(cb);
this.add(text2);
this.add(b);
this.add(text3);
this.setBounds(100, 100, 400, 100);
this.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
this.setVisible(true);
}
public static void main(String[] args){
new JSimpleComputer();
}
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getSource() == b){
int number1 = Integer.parseInt(text1.getText());
int number2 = Integer.parseInt(text2.getText());
if(cb.getSelectedIndex() == 0){
text3.setText(number1 + number2 +"");
}else if(cb.getSelectedIndex() == 1){
text3.setText(number1 - number2 + "");
}else if(cb.getSelectedIndex() == 2){
text3.setText(number1 * number2 + "");
}else if(cb.getSelectedIndex() == 3){
if(text2.getText().equals("0") ){
JOptionPane.showMessageDialog(null, "除数不能为0", "系统提示", JOptionPane.PLAIN_MESSAGE);
}else{
text3.setText(number1/number2 + "");
}
}
}
}
}
我直接给答案吧 请采纳 想知道第二题 再给点分数啊
public class JThreadPrinter implements Runnable
{
private String tag;
private int a = 0;
private char b = 'A';
public JThreadPrinter(String tag){
this.tag = tag;
}
public static void main(String[] args){
JThreadPrinter printer = new JThreadPrinter("A");
JThreadPrinter printer2 = new JThreadPrinter("B");
Thread t = new Thread(printer);
Thread t2 = new Thread(printer2);
t.start();
t2.start();
}
public void run(){
if(tag.equals("A")){
while(true){
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(a);
if(a == 9){
a = 0;
}else{
a++;
}
}
}else{
while(true){
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(b);
if(b == 'Z'){
b = 'A';
}else{
b++;
}
}
}
}
}
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class JSimpleComputer extends JFrame implements ActionListener
{
private JTextField text1;
private JTextField text2;
private JTextField text3;
private JComboBox cb;
private JButton b;
public JSimpleComputer(){
text1 = new JTextField();
text2 = new JTextField();
text3 = new JTextField();
Vector<String> vector = new Vector<String>();
vector.add("+");
vector.add("-");
vector.add("*");
vector.add("/");
cb = new JComboBox(vector);
b = new JButton("=");
b.addActionListener(this);
Dimension preferredSize = new Dimension(50,30);
text1.setPreferredSize(preferredSize);
text2.setPreferredSize(preferredSize);
text3.setPreferredSize(preferredSize);
this.add(text1);
this.add(cb);
this.add(text2);
this.add(b);
this.add(text3);
this.setBounds(100, 100, 400, 100);
this.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
this.setVisible(true);
}
public static void main(String[] args){
new JSimpleComputer();
}
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getSource() == b){
int number1 = Integer.parseInt(text1.getText());
int number2 = Integer.parseInt(text2.getText());
if(cb.getSelectedIndex() == 0){
text3.setText(number1 + number2 +"");
}else if(cb.getSelectedIndex() == 1){
text3.setText(number1 - number2 + "");
}else if(cb.getSelectedIndex() == 2){
text3.setText(number1 * number2 + "");
}else if(cb.getSelectedIndex() == 3){
if(text2.getText().equals("0") ){
JOptionPane.showMessageDialog(null, "除数不能为0", "系统提示", JOptionPane.PLAIN_MESSAGE);
}else{
text3.setText(number1/number2 + "");
}
}
}
}
}
我直接给答案吧 请采纳 想知道第二题 再给点分数啊
public class JThreadPrinter implements Runnable
{
private String tag;
private int a = 0;
private char b = 'A';
public JThreadPrinter(String tag){
this.tag = tag;
}
public static void main(String[] args){
JThreadPrinter printer = new JThreadPrinter("A");
JThreadPrinter printer2 = new JThreadPrinter("B");
Thread t = new Thread(printer);
Thread t2 = new Thread(printer2);
t.start();
t2.start();
}
public void run(){
if(tag.equals("A")){
while(true){
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(a);
if(a == 9){
a = 0;
}else{
a++;
}
}
}else{
while(true){
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(b);
if(b == 'Z'){
b = 'A';
}else{
b++;
}
}
}
}
}
追问
朋友,非常感谢你能帮我,悬赏最高是200,那我再提问一次吧还剩150都给你了
追答
不用了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询