Instructions
Requirements and Specifications
Source Code
import java.util.Scanner;
public class ComputingTotal {
public static int update(int presentTotal, int newNumber) {
return presentTotal + newNumber;
}
public static void main(String[] args) {
int total = 0, input;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter up to 15 numbers next. "
+ "One number per line. Terminate with 0.");
for(int i = 0; i < 15; i++) {
input = keyboard.nextInt();
if(input == 0)
break;
total = update(total, input);
}
System.out.println("Your final total is " + total);
}
}
public static void nonMultiple(int from, int to, int num) {
if(from >= to) {
System.out.println("Invalid parameters");
return;
}
for(int i = from; i <= to; i++) {
if(i % num != 0)
System.out.println(i);
}
}
public static void main(int hhh, int www) {
if(hhh <= 0 || www <= 0) {
system.out.println("Both parameters must be positive");
return;
}
for(int r = 0; r < hhh; r++) {
for(int i = 0; i < r; i++)
System.out.print(" ");
for(int c = 0; c < www; c++)
System.out.print("#");
System.out.println();
}
}
public static boolean thirdToken(String w) {
Scanner sc = new Scanner(w);
if(!sc.hasNext()) return false;
sc.next();
if(!sc.hasNext()) return false;
sc.next();
return sc.hasNextInt();
}
02, 03, 04, 05, 06, 09, 10, 11, 12, 13
After line 1 z is equal to 25 and w is equal to 0
After line 2 z is equal to 625 and w is equal to -1