Below is a simple Java program to print a table using loops and Math.pow() function. Alternative solution to Introduction to…
Write a program that plays the popular scissor-rockpaper game. (A scissor can cut a paper, a rock can knock a…
Java program that lets the user guess whether the flip of a coin results in heads or tails. The program…
Author: Y. Daniel LiangISBN: 0133761312 Year: 2014 Pages: 1344 Language: English File size: 14.38 MBFile format: PDFBook DescriptionThis text is…
Author: Harvey Deitel, Paul Deitel ISBN: 0133813436 Year: 2014 Pages: 1200 Language: English File size: 15.76 MB File format: PDF Book…
Java program that prompts the user to enter a month and year and displays the number of days in the…
Java program that prompts the user to enter an integer and checks whether the number is divisible by both 5…
Java program ComputeAndInterpretBMI.java, to let the user enter weight, feet, and inches and calculate and interpret the user BMI whether…
Program that prompts the user to enter the first 9 digits of an ISBN number and displays the 10-digit ISBN…
Program that randomly generates an addition question with two integers less than 100.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> */<br /><br />import java.util.Scanner;<br /><br />public class Ex03_10 {<br /> public static void main(String[] args) {<br /> // Generate two integers less than 100<br /> int number1 = (int) (Math.random() * 100);<br /> int number2 = (int) (Math.random() * 100);<br /><br /> // Prompt the user to answer "What is number1 + number2?"<br /> System.out.print("What is " + number1 + " + " + number2 + "? ");<br /> Scanner input = new Scanner(System.in);<br /> int answer = input.nextInt();<br /> // Grade the answer and display the result<br /> if (number1 + number2 == answer) {<br /> System.out.println("You are correct!");<br /> } else {<br /> System.out.println("Your answer is wrongn" + number1 + " + " + number2 + " is "<br /> + (number1 + number2));<br /> }<br /> }<br />}<br /> |
Sample program runClick here to see other solutions…
Program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is…
Program that generates two integers under 100 and prompts the user to enter the sum of these two integers.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> */<br /><br />import java.util.Scanner;<br /><br />public class Ex03_04 {<br /> public static void main(String[] args) {<br /> int number1 = (int)(System.currentTimeMillis() % 100);<br /> int number2 = (int)(System.currentTimeMillis() / 7 % 100);<br /> Scanner input = new Scanner(System.in);<br /> System.out.print("What is " + number1 + " + " + number2 + "? ");<br /> int answer = input.nextInt();<br /> System.out.println(number1 + " + " + number2 + " = " + answer + " is " <br /> + (number1 + number2 == answer));<br /> } <br />}<br /> |
Sample runClick…