Jump to content

Java newb needs help

Go to solution Solved by Xenift,

Create a loop which allows the user to enter multiple times till they want it to stop.

 

If it is exactly 10 grades to be entered, use a while loop.

int i = 1;

int total = 0;

while(i<10){

System.out.print("Enter grade: ");

total = sc.nextInt() + total;

}

 

Yadda yadda something like this.

 

sc in this case is the object, declare the object first like this...Scanner sc = new Scanner(System.in)

 

 

 

If it is more than lets say.....infinity.

use a do while loop

I have to create a project for school so i thought of an overview of grades, basicly a user enters 10 grades and gets the average grade of these. In math this would look somewhat like this: (Grade1 + Grade2 + Grade3 + ... + Grade10)/10. Now how do i translate this into java code?

My Rig: AMD Ryzen 5800x3D | Scythe Fuma 2 | RX6600XT Red Devil | B550M Steel Legend | Fury Renegade 32GB 3600MTs | 980 Pro Gen4 - RAID0 - Kingston A400 480GB x2 RAID1 - Seagate Barracuda 1TB x2 | Fractal Design Integra M 650W | InWin 103 | Mic. - SM57 | Headphones - Sony MDR-1A | Keyboard - Roccat Vulcan 100 AIMO | Mouse - Steelseries Rival 310 | Monitor - Dell S3422DWG

Link to comment
https://linustechtips.com/topic/487262-java-newb-needs-help/
Share on other sites

Link to post
Share on other sites

11 variables, sum up the first 10 and save them in the 11th, then divide the 11th by 10.

Remember kids, the only difference between screwing around and science is writing it down. - Adam Savage

 

PHOΞNIX Ryzen 5 1600 @ 3.75GHz | Corsair LPX 16Gb DDR4 @ 2933 | MSI B350 Tomahawk | Sapphire RX 480 Nitro+ 8Gb | Intel 535 120Gb | Western Digital WD5000AAKS x2 | Cooler Master HAF XB Evo | Corsair H80 + Corsair SP120 | Cooler Master 120mm AF | Corsair SP120 | Icy Box IB-172SK-B | OCZ CX500W | Acer GF246 24" + AOC <some model> 21.5" | Steelseries Apex 350 | Steelseries Diablo 3 | Steelseries Syberia RAW Prism | Corsair HS-1 | Akai AM-A1

D.VA coming soon™ xoxo

Sapphire Acer Aspire 1410 Celeron 743 | 3Gb DDR2-667 | 120Gb HDD | Windows 10 Home x32

Vault Tec Celeron 420 | 2Gb DDR2-667 | Storage pending | Open Media Vault

gh0st Asus K50IJ T3100 | 2Gb DDR2-667 | 40Gb HDD | Ubuntu 17.04

Diskord Apple MacBook A1181 Mid-2007 Core2Duo T7400 @2.16GHz | 4Gb DDR2-667 | 120Gb HDD | Windows 10 Pro x32

Firebird//Phoeniix FX-4320 | Gigabyte 990X-Gaming SLI | Asus GTS 450 | 16Gb DDR3-1600 | 2x Intel 535 250Gb | 4x 10Tb Western Digital Red | 600W Segotep custom refurb unit | Windows 10 Pro x64 // offisite backup and dad's PC

 

Saint Olms Apple iPhone 6 16Gb Gold

Archon Microsoft Lumia 640 LTE

Gulliver Nokia Lumia 1320

Werkfern Nokia Lumia 520

Hydromancer Acer Liquid Z220

Link to comment
https://linustechtips.com/topic/487262-java-newb-needs-help/#findComment-6539605
Share on other sites

Link to post
Share on other sites

Create a loop which allows the user to enter multiple times till they want it to stop.

 

If it is exactly 10 grades to be entered, use a while loop.

int i = 1;

int total = 0;

while(i<10){

System.out.print("Enter grade: ");

total = sc.nextInt() + total;

}

 

Yadda yadda something like this.

 

sc in this case is the object, declare the object first like this...Scanner sc = new Scanner(System.in)

 

 

 

If it is more than lets say.....infinity.

use a do while loop

Link to comment
https://linustechtips.com/topic/487262-java-newb-needs-help/#findComment-6539617
Share on other sites

Link to post
Share on other sites

11 variables, sum up the first 10 and save them in the 11th, then divide the 11th by 10.

And how would that look in code? Really confused about this. 

Grade1 + Grade2 + ... = x;

x / 10 = Average;

My Rig: AMD Ryzen 5800x3D | Scythe Fuma 2 | RX6600XT Red Devil | B550M Steel Legend | Fury Renegade 32GB 3600MTs | 980 Pro Gen4 - RAID0 - Kingston A400 480GB x2 RAID1 - Seagate Barracuda 1TB x2 | Fractal Design Integra M 650W | InWin 103 | Mic. - SM57 | Headphones - Sony MDR-1A | Keyboard - Roccat Vulcan 100 AIMO | Mouse - Steelseries Rival 310 | Monitor - Dell S3422DWG

Link to comment
https://linustechtips.com/topic/487262-java-newb-needs-help/#findComment-6539626
Share on other sites

Link to post
Share on other sites

You only really need 1 variable. Make a for loop for Scanner.nextInt() and just add to that variable. At the end just divide it by 10.

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/487262-java-newb-needs-help/#findComment-6539633
Share on other sites

Link to post
Share on other sites

I habe no Java knowledge ( Yet ) but consider the fact that some teachers make like your test 80% of the final and homework 20% ect.

 

 

i7-6700k  Cooling: Deepcool Captain 240EX White GPU: GTX 1080Ti EVGA FTW3 Mobo: AsRock Z170 Extreme4 Case: Phanteks P400s TG Special Black/White PSU: EVGA 850w GQ Ram: 64GB (3200Mhz 16x4 Corsair Vengeance RGB) Storage 1x 1TB Seagate Barracuda 240GBSandisk SSDPlus, 480GB OCZ Trion 150, 1TB Crucial NVMe
(Rest of Specs on Profile)

Link to comment
https://linustechtips.com/topic/487262-java-newb-needs-help/#findComment-6539726
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×