Write a program that counts down from 10 Implement your prog
Write a program that counts down from 10. Implement your program first with a while loop. Now implement your program with a for loop. Include both versions in your submission file. Write a program that prints 2^n2n where n goes from 1 to 100. Print one answer per line (note: you are answering the question, how high can you count on 100 fingers). Write your program using a \'for\' loop. Reminder \'**\' is the operator for exponents, so for example 4**3 is 4 to the third power, or 4 * 4 * 4 which equals 64. E.g. 2 4 8 16 .... Extend your guessing game from last week. Write a program that picks a random number from 1-100. Then ask the user to guess a number. Tell the user if the answer is higher or lower than the number they guessed, or if they got the correct answer. Allow them to guess again if they got the guess incorrect. They should be able to guess numbers an infinite number of times until they get the correct answer, at which point your loop will end. To generate a number from 1-100 you will need the following code at the beginning of your program: from random import randint randomNum = randint(1,100) Extra Credit - 5 possible points - Write a program that generates the multiplication table for numbers 1-10. Use two for loops to complete your program. You will need to put one for loop inside of the other for loop. As an extra challenge, see if you can get the indention to look correct. So the output of your program should be: 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81
Solution
Note you please clearly give description abount 2^n2n program and Remainder \'**\".So that I can understand and post the program.And please post the due date also. So that I will post immediately.
______________________________
Program which display the countdown using while Loop
CountDownUsingWhile.java
public class CountDownUsingWhile {
public static void main(String[] args) {
//Declaring variable
int i=10;
//checking whether the number is greater than zero or not.
while(i>0)
{
//Displaying the number
System.out.println(i);
//Decrementing the \'i\' value by 1 for every iteration
i--;
}
}
}
___________________________________
Output:
10
9
8
7
6
5
4
3
2
1
______________________________________
Program which display the countdown using for Loop
CountDownUsingForLoop.java
public class CountDownUsingForLoop {
public static void main(String[] args) {
//This for loop will display the number from 10 to 1
for(int i=10;i>0;i--)
{
//Displaying the numbers
System.out.println(i);
}
}
}
______________________________________
Output:
10
9
8
7
6
5
4
3
2
1
_________________________________________
___________________________________
GuessingNumberGame.java
import java.util.Random;
import java.util.Scanner;
public class GuessingNumberGame {
public static void main(String[] args) {
//Declaring variables
int random_num, guess_num;
/* Scanner class object is used to read
* the inputs entered by the user
*/
Scanner sc = new Scanner(System.in);
random_num = randint(1,100);
//This loop continue to execute until user guessed the exact number
while (true) {
/* This loop continue to execute until user
* enters a valid number between 1 and 100 inclusive
* If guessed out of range number.Then it will displays error
* message and prompts the user to guess again
*/
while (true) {
//Getting the number entered by the user
System.out.print(\"Guess The number :\");
guess_num = sc.nextInt();
//Checking whether the user guessed number is with in range or not
if (guess_num < 1 || guess_num > 100) {
System.out.println(\"::Invalid number.Number Must be between 1 and 100(Inclusive)::\");
continue;
} else
break;
}
/* If the generated number and guessed number are
* same then display message and program will exit.
* If not display messages and prompts to enter again.
*/
if (random_num == guess_num) {
System.out.println(\":: Guessed Exact number ::\");
break;
} else if (random_num > guess_num) {
System.out.println(\"::Guess Higher Number ::\");
continue;
} else if (random_num < guess_num) {
System.out.println(\"::Guess Lower Number ::\");
continue;
}
}
}
private static int randint(int i, int j) {
//Creating the Random class object
Random r = new Random();
//Generating the random number between 1 and 100 inclusive
return r.nextInt((j - i) + 1) + i;
}
}
____________________________________
Output:
Guess The number :50
::Guess Higher Number ::
Guess The number :60
::Guess Lower Number ::
Guess The number :55
::Guess Higher Number ::
Guess The number :58
::Guess Higher Number ::
Guess The number :59
:: Guessed Exact number ::
________________________
Progrm which display Multiplication Tables
MultiplicationTable.java
public class MultiplicationTable {
public static void main(String[] args) {
//Thsi nested for loop will print the multiplication table from 1 to 10
for(int i=1;i<10;i++)
{
for (int j=1;j<10;j++)
{
System.out.print(i*j+\" \");
}
}
}
}
________________________________
Output:
1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81
_____________________________________



