Answer to Question #2181 in Java | JSP | JSF for Kamile

Question #2181
Please enter three integer values:
12 15 3
The sum of these numbers is:30

this is how my output suppose to look like, am using Jcreator (JAVA), the values must be added using a loop.Values come from user as well
1
Expert's answer
2011-06-24T07:37:33-0400
import java.util.Scanner;

public class Task {
& public static void main(String[] args)
& {
int result = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter three integer values:");
for(int i = 0; i < 3; i++)
{
if(scan.hasNextInt())
{
& result += scan.nextInt();
}
}
System.out.println("The sum of these numbers is:"+result);
& }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS