Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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]));
}
}
Posted
Updated 27-Apr-16 4:21am
Comments
Sergey Alexandrovich Kryukov 27-Apr-16 9:31am    
The question makes no sense. There is no such thing, "run it in GUI" — what "it"? You did not explain why doing so (I understand, to learn UI programming), what exactly it should do, and so on.
—SA
Member 12488488 27-Apr-16 9:48am    
it makes perfect sense, the code i wrote there runs in a console!! like i said i dont know how to run the program on a GUI..
Sergey Alexandrovich Kryukov 27-Apr-16 11:17am    
It's not "run", it's develop new code, UI... You are talking about nothing, essentially. If you want to develop UI, develop the UI. Ask your question when and if you have some problems.
—SA
Mohibur Rashid 28-Apr-16 5:07am    
This code is not going to run on GUI.
Fundamental of GUI programming and console base programming are very different from each other.
If you are learning Java programming, console programming is suppose to be fine.
If you are learning GUI Programming with java, its whole different story. It does not go with the requirements you have made. In the learning process you will have to learn and understand whole different area:
-> how gui handle window
-> how gui handle control
-> how gui handle user request
and so on.

I believe, your programming skill is not good "yet". May be, you better stick to learning basic programming in console mode first.

Finally one small non programming related note: your response "it makes perfect sense" does not improve your question, but it identifies you as arrogant.
Member 12488488 28-Apr-16 8:07am    
Thanks.. Yes i know this code wont run in GUI, that's just what i have done concerning the program i said i was writing. and that runs in console, any help on running the same program(not the same code)on GUI??

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900