This is the work
- From the main method call a method named sumOfDigits(), without passing any parameters
- Create a method named sumOfDigits()
- In the sumOfDigits() method declare the variable N of type int
- Assign the value 100 to the variable N.
- Using the sum of digits formula: (1 + N)*(N/2)
print the total amount of the sum of digits from 1 to 100
__________________________________________________ __________________________
ive tried using
public void sumOfNumbers() {
formula = (1+100)*(2/100)
}
then I do system print (formula) but it keeps displaying 0
ive been messing around with it also. this is my code so far
__________________________________________________ _________
package Lunix;
public class chaplew {
private String myName;
private double creditsTaken;
private double totalCredits;
private double GPA;
private String major;
private String className;
private int maxValue;
private double N;
public chaplew(String myName, double creditsTaken,
double totalCredits, double GPA, String major, String className, int maxValue, int N )
{
this.myName = myName;
this.GPA = GPA;
this.className = className;
this.major = major;
this.totalCredits = totalCredits;
this.creditsTaken = creditsTaken;
this.maxValue = maxValue;
this.N = N;
}
public String getmyName()
{
return myName;
}
public double getcreditsTaken()
{
return creditsTaken;
}
public double gettotalCredits()
{
return totalCredits;
}
public double gteGPA()
{
return GPA;
}
public String getmajor()
{
return major;
}
public String getclassName()
{
return className;
}
public void addNumbers(int addition)
{
maxValue = addition+1;
}
public void subtractNumbers(int subtraction)
{
maxValue = subtraction-1;
}
public void multiplyNumbers(int multiply)
{
maxValue = multiply*1;
}
public void divideNumbers(int divide)
{
maxValue = divide/1;
}
public void modNumbers(int mod)
{
maxValue = mod%1;
}
public void sumOfNumbers(int form)
{
N = form;
}
public static void main(String[] args) {
// TODO code application logic here
chaplew p = new chaplew("William", 9, 70, 3.1, "Information Technology", "Operating Systems", 100, 1);
System.out.println("my name is...." + p.myName);
System.out.println("credits I am enrolled is..." + p.creditsTaken);
System.out.println("I have taken this amount of credits throughout college..." + p.totalCredits);
System.out.println("My gpa is..." + p.GPA);
System.out.println("My Major is.." + p.major);
System.out.println("This class is called......." + p.className);
System.out.println();
p.addNumbers(100);
System.out.println("Max Value 1 + 2 + 3 + 4 + 5");
System.out.println(p.maxValue);
System.out.println(p.maxValue+(1));
System.out.println(p.maxValue+(2));
System.out.println(p.maxValue+(3));
System.out.println(p.maxValue+(4));
p.subtractNumbers(100);
System.out.println();
System.out.println("Max Value 1 - 2 - 3 - 4 - 5");
System.out.println(p.maxValue-1);
System.out.println(p.maxValue-2);
System.out.println(p.maxValue-3);
System.out.println(p.maxValue-4);
System.out.println(p.maxValue-5);
p.multiplyNumbers(100);
System.out.println();
System.out.println("Max Value 1 * 2 * 3 * 4 * 5");
System.out.println(p.maxValue*1);
System.out.println(p.maxValue*2);
System.out.println(p.maxValue*3);
System.out.println(p.maxValue*4);
System.out.println(p.maxValue*5);
p.divideNumbers(100);
System.out.println();
System.out.println("Max Value 1 / 2 / 3 / 4 / 5");
System.out.println(p.maxValue/1);
System.out.println(p.maxValue/2);
System.out.println(p.maxValue/3);
System.out.println(p.maxValue/4);
System.out.println(p.maxValue/5);
p.modNumbers(100);
System.out.println();
System.out.println("Max Value 1 % 2 % 3 % 4 % 5");
System.out.println(p.maxValue%1);
System.out.println(p.maxValue%2);
System.out.println(p.maxValue%3);
System.out.println(p.maxValue%4);
System.out.println(p.maxValue%5);
System.out.println();
p.addNumbers((1+100)*(2/100));
System.out.println((1+100)*(2/100));
}
}