1. Display random numbers to simulate rolling a die 2. Create a java program tha
ID: 3556084 • Letter: 1
Question
1. Display random numbers to simulate rolling a die
2. Create a java program that simulate a casino game. (rollin a die)
a. To play a game, pay $1
b. The rewards are;
6: $3
5: $ 0
4: $0
3: $0
2: $0
1: $4
Display the balance of the game.
3. Write a program that prints a multiplication table, like the following"
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
4. Write a program that reads a word and print the word in reverse. For example, if the user provides the input "harry", the program prints " yrrah".
5. Write a java program that create the Power table program as the following table ( PowerTable.java)
1 2 3 4
x x x x
1 1 1 1
2 4 8 16
3 9 27 81
---
10 100 1000 10000
5 .jar files and codes for the 5 project above
Explanation / Answer
1)
2)
3)
public class mult{
public static void main(String[] args) {
int[][] multtable = new int[11][11];
System.out.print("*");
for (int a=1;a<=size;a++)
{
System.out.print(" "+a) ;
}
System.out.println(" ");
for(int i=0; i<=10; i++)
{
// this loop is for rows
for(int j=0; j<=10; j++)
{
// this loop is for columns
multtable[i][j] = i*j;
}
}
System.out.print(" ");
System.out.print("------------------------------");
System.out.println("");
for(int i=1; i<11; i++)
{
System.out.print(i+"| ");
for(int j=1; j<11; j++)
{
// this ensures that all single-digit numbers will line up into columns
System.out.print(multtable[i][j]+" ");
}
// make a new line for every row
System.out.print(" ");
}
}
}
4)
import java.util.Scanner;
public class Powers
{
public static void main(String[] args)
{
System.out.println("Welcome to the Squares and Cubes Table");
System.out.println();
Scanner sc = new Scanner(System.in);
String choice = "y";
while(choice.equalsIgnoreCase("y"))
{
// get the input from the user
System.out.println("Enter an Integer: ");
int integerNext = sc.nextInt();
System.out.println("Number" + " " + "Squared" + " " + "Cubed");
System.out.println("======" + " " + "======" + " " + "======");
for (int i = 1; i <= integerNext; i++) {
int numberSquared = (int) Math.pow(i, 2);
int numberCubed = (int) Math.pow(i, 3);
String message = " " + i + " " + numberSquared + " " + numberCubed;
System.out.print(message);
}
// see if the user wants to continue
System.out.print(" Continue? (y/n): ");
choice = sc.next();
System.out.println();
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.