# Thread: Simple coding help (integers)

1. Member
Join Date
Aug 2013
Posts
2
Rep Power
0

## Simple coding help (integers)

So I'm having some trouble with a bit of simple code I'm trying to write to print a set of 4 numbers input by the user then calculate the average of those numbers. For some reason I keep getting an error when try to enter the numbers. The program also has to print two words before the numbers in the correct format. Here's what I've done

public static void main(String[] args)
{Scanner scan = new Scanner (System.in);
String heading1 = "Word1";
String heading2 = "Word2";
String heading3 = "Num1";
String heading4 = "Num2";
String heading5 = "Num3";
String heading6 = "Num4";
String heading7 = "Total";

double Total;
scan.useDelimiter("[,]");

String Word1= scan.next();
String Word2= scan.next();

int Num1=scan.nextInt();
int Num2=scan.nextInt();
int Num3=scan.nextInt();
int Num4=scan.nextInt();

Total=(Num1*0.1)+(Num2*0.4)+(Num3*0.2)+(Num4*0.3);
System.out.printf("%-15s %14s %5s %10s %10s %10s %10s %n", Word1, Word2, Num1, Num2, Num3, Num4, Total);

The error occurs as soon as the program reaches the number integers (it has no problem with the words). Any help you can provide would be greatly appreciated because I just can't figure out what's going on here.

2. Member
Join Date
Aug 2013
Posts
2
Rep Power
0

## Re: Simple coding help (integers)

Sorry, to correct myself, it isn't an average, it's the sum listed next to Total (Num1*0.1)+(Num2*0.4)+(Num3*0.2)+(Num4*0.3)

3. ## Re: Simple coding help (integers)

Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

You might also get better responses by learning How to ask questions the smart way

db

4. ## Re: Simple coding help (integers)

Don't use that delimeter and type your entire input on one line separated by spaces and see ...

kind regards,

Jos

5. ## Re: Simple coding help (integers)

Another recommendation: Code Conventions for the Java Programming Language: Contents

Variable names should begin with a lowercase letter. Also learn how to indent code correctly.

db

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•