Thursday, November 15, 2012

Javascript Working With While Loops Part 2




//CSC 15 Lab5 Part 2 Indefinit loops
//Christopher Smith
//

import java.util.Scanner; //importing scanner class

public class lab5p2 {
public static void main (String[] args){
int count; //variable for prompt
int sum; //total sum of counts
int max; //stored highest value
int input; //user input

Scanner keyboard = new Scanner (System.in); //defining variable for keyboard input

System.out.println("Enter a number to be summed"); //text for input
System.out.println("While the number is greater than zero, it'll keep summing");
input = keyboard.nextInt(); //enter prompt

//starting while loop
sum = 0; //clearing
max = 0; //clearing
count = 0; //clearing
while (input > 0)
{
if (input > max)//checking for highest entered value
{
max = input;
}

count = count + input;

System.out.println("Enter your next value");
input = keyboard.nextInt(); //prompting for new input
}

System.out.println("The total sum is: "+count);
System.out.println("The highest value was: "+max);
}
}

No comments:

Post a Comment