如何在GUI中生成以下程序的输出? (Java新手)谢谢.. [英] How do I produce the output of the program below in a GUI? (New to java) thanks..

查看:53
本文介绍了如何在GUI中生成以下程序的输出? (Java新手)谢谢..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个程序,它接受五个整数的输入并将它们存储在一个数组中,然后打印出第二个和第五个值之和。嗯,这是我能够做到的,但这是在一个控制台运行..任何有关如何在GUI上运行它的帮助?谢谢。



我尝试过:



import java.util .Scanner;

类IntSum {

public static void main(String [] args){

Scanner sc = new Scanner(System.in );

int [] arr = new int [5];

System.out.println(输入5个整数);

for(int i = 0; i< 5; i ++){

arr [i] = sc.nextInt();

}

System.out.println(第2和第5个元素的总和是+(arr [1] + arr [4]));

}

}

解决方案

请参阅跟踪:使用JFC / Swing创建GUI (The Java Tutorials) [ ^ ]。

Im trying to write a program that takes input of five integers and stores them in an array and then then prints out the sum of just the second and fifth value. Well this is what i have been able to do, but this runs in a console.. any help on how to run it on a GUI? Thanks.

What I have tried:

import java.util.Scanner;
class IntSum{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int[] arr=new int[5];
System.out.println("Enter 5 integers");
for(int i=0;i<5;i++){
arr[i]=sc.nextInt();
}
System.out.println("Sum of 2nd and 5th element is "+(arr[1]+arr[4]));
}
}

解决方案

See Trail: Creating a GUI With JFC/Swing (The Java Tutorials)[^].


这篇关于如何在GUI中生成以下程序的输出? (Java新手)谢谢..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆