The Artima Developer Community
Sponsored Link

Java Answers Forum
Method help

1 reply on 1 page. Most recent reply: Nov 16, 2008 8:56 PM by William Robertson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Mike williams

Posts: 3
Nickname: jpnym15
Registered: Nov, 2008

Method help Posted: Nov 14, 2008 8:46 AM
Reply to this message Reply
Advertisement
import java.util.*;

public class Summer

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

Scanner in = new Scanner(System.in);
int first = 0;
int last = 0;
int total = 0;
int i = 0;

System.out.println("Hello. I will calculate the sum");
System.out.println("of consecutive integers.");
System.out.println("Please enter the starting number:");
first = in.nextInt();
System.out.println("Please enter the ending number:");
last = in.nextInt();

while (last < first)
{
System.out.println(last + " is smaller than " + first);
System.out.println("The ending number must be bigger than the first");
System.out.println("Enter the starting number again");
first = in.nextInt();
System.out.println("Enter the ending number again");
last = in.nextInt();
System.out.println("The sum of the numbers are " + total);

}


{
for (i = first; i <= last; i++)

total = total + i;
}
}
}


although the code is fine with the way it is now, I need to be able to put another user defined method into this to get the answer...any ideas how it can be done..


William Robertson

Posts: 6
Nickname: billr42
Registered: May, 2008

Re: Method help Posted: Nov 16, 2008 8:56 PM
Reply to this message Reply
You might start by reading the textbook that your professor recommended.

Flat View: This topic has 1 reply on 1 page
Topic: How to implement a JTextArea that shows the messages coming in the console? Previous Topic   Next Topic Topic: Adding a binary file to the BLOB column through command line in MSSQL

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use