While Loops #67 (It's an If statement within an If statement.)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name:Loop Values
/// File Name:Loop Values.java
/// Date Finished: 12/10/2015
import java.util.Scanner;
public class AddLoopValues
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int guess = 0;
System.out.println();
System.out.println( "I will add up the numbers you give me." );
System.out.print( "Number: " );
int origin = keyboard.nextInt();
guess = guess + origin;
if ( origin != 0 )
System.out.println( "The total so far is " + guess );
while ( origin != 0 )
{
System.out.print( "Origin: " );
origin = keyboard.nextInt();
guess = guess + origin;
if ( origin != 0 )
System.out.println( "The total so far is " + guess );
}
System.out.println();
System.out.println( "The total is " + guess );
System.out.println();
}
}
Picture(s) of the output