Need help with college homework about making a algotrthm

guys I need help with my homework basicly it wants me to make a algrothm in java to find the average of 4 numbers
74 Replies
JavaBot
JavaBot•3mo ago
āŒ› This post has been reserved for your question.
Hey @demon737sword! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
ayylmao123xdd
ayylmao123xdd•3mo ago
is it a list are the numbers in a list or are they separate variables
demon737sword
demon737swordOP•3mo ago
it wasnt specific about that
ayylmao123xdd
ayylmao123xdd•3mo ago
did you have lists or arrays before or no
demon737sword
demon737swordOP•3mo ago
no Im current;y restarting from scratch and have no idea what im doing
ayylmao123xdd
ayylmao123xdd•3mo ago
ok lets just do normal variables then do you know how to make a variable
demon737sword
demon737swordOP•3mo ago
uhhh i might idk I just started this class for college
ayylmao123xdd
ayylmao123xdd•3mo ago
do you know how to run a java program like the main class
demon737sword
demon737swordOP•3mo ago
I think so currently it doesnt work on the school computers
ayylmao123xdd
ayylmao123xdd•3mo ago
public static void main(String[] args) {

}
public static void main(String[] args) {

}
have you ever seen this
demon737sword
demon737swordOP•3mo ago
yes
ayylmao123xdd
ayylmao123xdd•3mo ago
ok so its like very beginner stage java yes that u have rn
demon737sword
demon737swordOP•3mo ago
yes
ayylmao123xdd
ayylmao123xdd•3mo ago
ok then declare 4 int variables and send the code here
int number1 = 10;
int number1 = 10;
etc
demon737sword
demon737swordOP•3mo ago
ok so I just put that down 4 teams in between the brackets
ayylmao123xdd
ayylmao123xdd•3mo ago
that would make it an array like
int[] numbers [1,2,3,4]
int[] numbers [1,2,3,4]
demon737sword
demon737swordOP•3mo ago
yeah
ayylmao123xdd
ayylmao123xdd•3mo ago
so which option do you want
int number1 = 10;
int number2 = 5;
int number1 = 10;
int number2 = 5;
or what i sent earlier
demon737sword
demon737swordOP•3mo ago
this one
ayylmao123xdd
ayylmao123xdd•3mo ago
then make 4 numbers and paste the code here
demon737sword
demon737swordOP•3mo ago
\
No description
demon737sword
demon737swordOP•3mo ago
like that? now what?
ayylmao123xdd
ayylmao123xdd•3mo ago
now we sum it up šŸ™€ so do
int sum = number1 + number 2 +
int sum = number1 + number 2 +
` and so on
demon737sword
demon737swordOP•3mo ago
got it
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
no above the bracket } do you want the numbers to have decimals like 10.1 or no
demon737sword
demon737swordOP•3mo ago
well were trying to find the average so yeah
ayylmao123xdd
ayylmao123xdd•3mo ago
ok also add the semicolon at the end of the sum line and paste code
demon737sword
demon737swordOP•3mo ago
semicolomn added
ayylmao123xdd
ayylmao123xdd•3mo ago
show code
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
remove the space between number4 and semicolon
demon737sword
demon737swordOP•3mo ago
done
ayylmao123xdd
ayylmao123xdd•3mo ago
now swap all int to double and add
int average = sum / 4;
int average = sum / 4;
and after that
System.out.println(average);
System.out.println(average);
demon737sword
demon737swordOP•3mo ago
ok
ayylmao123xdd
ayylmao123xdd•3mo ago
keep in mind the results might return some crazy numbers like you do 1.1 as for all numbers it might return something like 1.09999999999999999999 but its normal for like beginner stuff
demon737sword
demon737swordOP•3mo ago
I dont care I want it to work
demon737sword
demon737swordOP•3mo ago
gave me this error when I tried runing it
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
send screenshot of your editor i mean the files on the lef t
demon737sword
demon737swordOP•3mo ago
shwo me what I should be looking for
ayylmao123xdd
ayylmao123xdd•3mo ago
you are using visual studio code right
demon737sword
demon737swordOP•3mo ago
ye
ayylmao123xdd
ayylmao123xdd•3mo ago
screenshot it all and send u can hide stuff u dont wanna sohw like ur name or something
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
ok so you dont have a jdk so its not gonna run i would say click the download jdk and install automatically would be ok however lets ask someone that has more help points than me lolololol @dan1st | Daniel no jdk and its vs code so i have no clue how to set it up
demon737sword
demon737swordOP•3mo ago
No description
demon737sword
demon737swordOP•3mo ago
whicnh ones?
ayylmao123xdd
ayylmao123xdd•3mo ago
also first whats youir file name the one where you are writing this code
demon737sword
demon737swordOP•3mo ago
Algorithm
ayylmao123xdd
ayylmao123xdd•3mo ago
i suggest you put that file in some folder and you have to name it with .java at the end otherwise its not gonna run
dan1st
dan1st•3mo ago
both work though I would personally either use the second one (if you are ok with the newest version) or install one from Adoptium and then using the third option
dan1st
dan1st•3mo ago
(that's adoptium) Also that's the Oracle extension lol Do you know the time in my timezone?
ayylmao123xdd
ayylmao123xdd•3mo ago
of course but you were typing 5 minutes ago in general
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
looks like we wait for it to load
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
show full screenshot
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
how did you run this
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
what if you right click on the code is there some option to run it
dan1st
dan1st•3mo ago
You could either enable preview features
demon737sword
demon737swordOP•3mo ago
no
dan1st
dan1st•3mo ago
or use a full main class
ayylmao123xdd
ayylmao123xdd•3mo ago
Kenny Yip Coding
YouTube
How to set up Java in Visual Studio Code
How to install Java with Visual Studio Code (vscode) in under 5 minutes. Install Visual Studio Code: https://code.visualstudio.com/ Install Java Coding Pack: https://code.visualstudio.com/docs/java/java-tutorial Open vscode, and create new file. Name it whatever you want, but be sure to include the .java extension. Ex) Create a file named Te...
ayylmao123xdd
ayylmao123xdd•3mo ago
also yea rename the file to Main.java and you need to have
demon737sword
demon737swordOP•3mo ago
No description
ayylmao123xdd
ayylmao123xdd•3mo ago
first rename the file to Main.java and your code should look like this
public class Main {
//the rest of the code here
}
public class Main {
//the rest of the code here
}
ok thats it for today im going amimir gonna check tomorrow
demon737sword
demon737swordOP•3mo ago
No description
dan1st
dan1st•3mo ago
add a main method and make sure the class name matches the file namw
JavaBot
JavaBot•3mo ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBot•3mo ago
Post Closed
This post has been closed by <@840262132649033779>.

Did you find this page helpful?