Odd numbers descending Learn programming Java

Lesson:

Flow Control


Exercise:

Odd numbers descending


Objetive:

Create a java program to display the odd numbers from 15 to 7 (downwards) on the screen using "while".


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		int num, multiplier = 1;

		System.out.print("Insert a number to multiply: ");
		num = Integer.parseInt(new Scanner(System.in).nextLine());

		while (multiplier <= 10)
		{
			System.out.printf("%1$s x %2$s = %3$s" + "\r\n", num, multiplier, num * multiplier);
			multiplier++;
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.