# java problem

Write a program that could be used to help children practise their subtraction problems. The
problems involve only integers between 10 and 99, inclusive. The program should start by
asking the user how many problems they would like to try, and read this value from the
keyboard. Then the program presents to the user that many problems and allows the user to
enter an answer for each. After user has input each answer, the program then display a
message indicating that the answer is correct, or if it is not correct, display the correct answer.
When all the problems are done, the program should print the percentage of problems answered
correctly.
Below is a sample run of such a program. The user input is shown in boldface.
How many problems would you like? 3
Question 1: What is 10 - 8? 2
Correct!
Question 2: What is 12 - 3? 8
No, 12 - 3 is 9
Question 3: What is 5 - 0? 5
Correct!
NOTE: a) The subtraction should not result in negative answer. That means if the first
integer is less than the second, you should swap the two randomly generated
integers so that the answer will always be non-negative.
b) Write the solution program in a single file called 'Subtraction.java'. Write the whole program inside the main method

March 18, 2010 at 3:10 PM

Hi Friend,

Try the following code:

import java.util.*;

public class Subtraction {
public static void main(String[] args) throws Exception {
int i=0;
int min=10, max=99;

Scanner scan = new Scanner(System.in);
Random random1 = new Random();
Random random2 = new Random();

System.out.print("How many problems would you like? ");
double q = scan.nextDouble();
System.out.println();
double r=0,w=0;

for (int idx = 1; idx <= q; ++idx){
i=i+1;
System.out.print("Question "+i+") ");
int ran1 = random1.nextInt(max - min + 1) + min;
int ran2 = random2.nextInt(max - min + 1) + min;
if(ran2>ran1){
ran1 = ran1 + ran2;
ran2 = ran1 - ran2;
ran1 = ran1 - ran2;
}
System.out.print(ran1 + " - " +ran2+" = ");
int sub=scan.nextInt();
int total=ran1-ran2;
if(sub!=total){
System.out.println("No, "+ran1+" - "+ran2+" is "+total);
w++;
}
else{
System.out.println("Correct");
r++;
}
}
double percent=r/q;

}
}

Thanks

java Problem
java Problem  I want to create a binary tree for displaying members in Downline. i am creating a site for MLM(Multi-Level MArketing). tree must be dynamically populated from database. is there any help for me. Thanks in advance
JAVA Problem
JAVA Problem  Write a program that takes two parameters 1. a word 2. an array of words It should then remove all instances of the word in the array. For Example: INPUT word="ravi" word_array = ["Chethan Bhagat
resolution problem in java
resolution problem in java  I designed project in java in my PC when run the same project in some other PC i can't fully view my java forms.Some said that it is resolution problem
Problem in uploading java application  I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... this problem
for a problem in coading - Java Beginners
for a problem in coading  what is the problm in following coading...(String[] args) { mywindow (); } }   Hi Friend, There is no problem... mywindows.java Run : java mywindows Thanks RoseIndia Team
Problem on JAVA Programme
Problem on JAVA Programme  public class AA { int add(int i) { int y = i; y += 20; if (y <= 100){ y +=30;add(y);} System.out.println("Final Value of y : " + y); return y; } public static void main
JAVA CLASSPATH PROBLEM
JAVA CLASSPATH PROBLEM  hi all Friends I am stuck using the java servlets and problem raise for classpath. I had a problem with servlet to call... that it didn't found any java class (which is java class calling from servlet). but i
Java implementation problem
/answers/viewqa/Java-Beginners/28578-java-implementation-problem-.html...Java implementation problem  I want to implement following in java... problem in your post previews. please consider 1. 2. points just after main
java implementation problem
java implementation problem   I want to implement following in java code : Main thread Create three threads wait for completion of stage 2 of all three threads Access all three local variable (LC0, LC1, LC2) of threads bulid
Basic problem for Java experts
Basic problem for Java experts  This assignment will test your knowledge of Arrays Array searching Array sorting Array processing Specification An athletics club require a simple statistical analysis program for analysing lap
java problem - Java Beginners
java problem  Write a program that could be used to help children...(); System.out.print("How many problems would you like? "); double q = scan.nextDouble(); System.out.println(); double r=0,w=0; for (int idx = 1; idx <= q
Java program problem
Java program problem  Hi, I took the chance to login here in your educational page due to my questions in mind about my java programming assignment... is a path to a directory. Example: java DuplicateFinder c:\Documents
java sms problem
java sms problem  i am developing web site in which i have to maintain sms system where one can message his/her detail and it should be stored in the database.please give me some idea how to maintain it as i am beginner.Thank you
java array problem
java array problem  suppose i have an array a[] at a[0] i have value 5,7 the thing is that i want to assign the value of array a[0]=5,7 to two variable let it be j,k that is j=5 and k=7 plz help regards
Java I/O problem
Java I/O problem   Write a Java application that prompts the user to input their Name, Address, Date of Birth and Student ID number using the standard input - this information should then be saved to a file named studentData
java core basic problem
java core basic problem  my question is: write a program that illustrates interface inheritance. interface P is extended by P1 and P2. interface... methode. class Q impliments P12 Instantiate Q and invoke each of its methods.Each
Java IF statement problem
Java IF statement problem  Dear Sir/Madam i am using the following code. expected to not have any output but it still showing "welcome".. please help me why it showing "welcome". class c1 { int a=5; while(a>1
java core basic problem
java core basic problem  my question is: write a program that illustrates interface inheritance. interface P is extended by P1 and P2. interface... methode. class Q impliments P12 Instantiate Q and invoke each of its methods.Each
Java code problem
Java code problem  Please check the errors,if any,in this code...i am a java beginner import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map
Java HashSet Collection problem
Java HashSet Collection problem  Here's how the HashSet works. It maintains an array of buckets. When an object is inserted, it finds the appropriate bucket corresponding to the objects HashCode. Then it calls the equals method
java textfield problem
java textfield problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here is the code
Java Web Browser Problem
Java Web Browser Problem  Hello When run my web browser this is not displaying complete page any of the website like other browser.So Plz help me. package vision.sun; import java.awt.Container; import
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets... method. Please help!!  Hi friend, Please explain problem in details for complete solution and send code the where are you problem. Thanks
can interface solve this problem in java
can interface solve this problem in java  I have a JDialog which... this calander class. can interface solve this problem. If yes then how. pls.../tutorial/java/swing/datePicker.html   thanks very much
java servlet connectivity problem with access
java servlet connectivity problem with access  Import java.sql javax.servlet //all packages entered try { Class.forName...=con.createStatement(); ^ i am confused what is the problem
problem
problem  hi'sir mai niit student hu.mujhe java ka program samaj me nhi aata mai kya karu and mai kaise study karu please help me.   Learn Java from the given link: Java Tutorials
problem regarding autoboxing - Java Beginners
problem regarding autoboxing    hello all , i have a problem regarding autoboxing Integer i = 127; Integer j = 127...://www.roseindia.net/java/ Thanks. Amardeep
problem in reading 10000 records in java
problem in reading 10000 records in java  Hi I have a huge records 10000 records ,while reading it show some error only i can able to read 2000 recds and need to display all the recods in jsper reports Thanks Gopi
problem with addactionlistener on JComboBox - Java Beginners
problem with addactionlistener on JComboBox  ViewElements.java:225: expected jccourse.addActionListener(new ActionListener()); ^ 1 error sir there is identifer expected error occur ,how i can solve
Open Jgraph Problem - Java Beginners
on this. I am a newbie in Java language. Thank you. Ulamraja
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example