Java application

Java application

public int remainder(int a, int b)
    {
        int answer = a % b;
        System.out.printf("%d % %d = ", a , b);
        return (answer);    
    }

and in my main, 

int answerRemain = calc.remainder (3,4);
        System.out.println (answerRemain);

and when i tried running it, it tells me:-
Exception in thread "main" java.util.IllegalFormatFlagsException: Flags = ' '
    at java.util.Formatter$FormatSpecifier.checkText(Formatter.java:2945)
    at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2647)
    at java.util.Formatter.parse(Formatter.java:2480)
    at java.util.Formatter.format(Formatter.java:2414)
    at java.io.PrintStream.format(PrintStream.java:920)
    at java.io.PrintStream.printf(PrintStream.java:821)

if i take out the % from "%d % %d = ", so that it is "%d %d" then it runs fine and gives the correct answer. my question is why wont it compile and, how can i print out the modulus sign so my output looks like 3 % 4 = 3. thank you!

View Answers

September 19, 2012 at 5:04 PM

We have modified your code. The character you want to display in the printf method is actually invalid.Therefore error occurs. Anyways, check your code.

class  FindRemainder
{
    public int remainder(int a, int b) { 
        int answer = a % b;
        System.out.println(a+" % "+b+" = " +answer);
        return (answer);
}
    public static void main(String[] args) 
    {
        FindRemainder f=new FindRemainder();
        f.remainder(3,4);
    }
}









Related Tutorials/Questions & Answers:
Java Application
Java Application  Hi, What is the applications of Java in development of software? What type of applications can be developed using Java programming Language? Can anyone tell me the url for downloading sample projects in Java
Java application - Java Beginners
Java application  Write a Java GUI application called Index.java that inputs several lines of text and a search character and uses String method indexOf to determine the number of occurrences of the character in the text
Advertisements
Java Client Application
Java Client Application  Java Client Application
Java Client Application example
Java Client Application example  Java Client Application example
Java HTML Client Application
Java HTML Client Application  Java HTML Client Application
JAVA APPLICATION - Java Beginners
JAVA APPLICATION   Hi, I have this question and I'm stuck. Please guide me? Thanks. Write a Java application to implement the program logic... with e : " + strAr[i]); } } } } For more information on Java visit
Batch file for java application
Batch file for java application  please tell me how to create the batch file for java application(using swings).the application is created with netbeans
java Application to java Applet
java Application to java Applet  sorry Java master disturb again how can i modify below this Java application to applet because in swtich case i had put this countinue selection source code to make user choosing so hope can
Java application - Java Beginners
Java application  Dear sir, I Designed a Window Throung Swing component Using JDBC. My Problem is that How and What component may used... the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml Hope
java reminder Application
java reminder Application  Create an awt application which imitates a reminder application,that stores notes and specify date and time to be reminded
java reminder Application
java reminder Application  Create an awt application which imitates a reminder application,that stores notes and specify date and time to be reminded
Fingerprint application with Java
Fingerprint application with Java  Hi, How to create fingerprint application with Java? Thanks   Hi, There are many API in Java which... application with Java. Here are few APIs: http://www.griaulebiometrics.com/en-us
java application - Framework
java application   Hi How to make .exe or a plateform independent executable file( i think its jar in case of java) of a java code. Thnx
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
Fax service in Java application.
Fax service in Java application.  Hello, I want to develop a Java application to send fax to any destination fax numbers. Anyone who knows about this, please tell how I can do this. Is there any free libraries
chat application - Java Beginners
chat application  i hv created a chat application , but i hav facing problem when i run it in lan , pc ping but apllication doent giv ressponce plz help for these if some one have work on java chat application my email id
Java application PLZ ?
Java application PLZ ?  Write an application that demonstrates each of the following methods, based on the statement String dedicate = ?Dedicated to making your event a most memorable one:; indexOf(?D?) charAt(15) endsWith(one
Drools Application in Java
Drools Application in Java  when I have make a drools application using java and eclipse i have a facing a error Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService' I was searching
Java web Application
Java web Application  Hi! I have developed a java web application project using netbean IDE with glassfish server. My question is how to create a runnable file from this. How can we make it to a single file? I think it is war
Problem in uploading java application
Problem in uploading java application  I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... application it is showing javax.servlet.ServletException: Parse Error in JSP page
Fingeprint matching in java application
Fingeprint matching in java application  I am developing a java application which require fingerprint identification and verification. It is a webservice application. following considration we have to take in to mind. 1. if I am
Distributed application and java
Distributed application and java  Hi, Am about to develop a Java swing application. This software will be used by 20 branch offices and every... like to go forward with the Java swing application only for this. And the way
Constructing Application of Java
Constructing Application of Java   Hi,I am doing project on java as front end and database as back end.I completed it almost on my computer but now I want to distribute it to some other computer.so have to convert the java source
Java application Help?
Java application Help?  Write an application that accepts a users password from the keyboard. When the entered password is less then six characters more then 10 characters, or does not contain at lease one letter and one digit
java web application - Ant
java web application  hai, iam new to J2EE. i've installed jdk... tell me the steps to build and deploy a small web application on MyEclipse?(like HelloWorld).Please tell me the directory structure to place my java classes
Java application that uses the classes and
Java application that uses the classes and   i have this class diagram with three classes: Curriculum, Course, and Lecture. Your class diagram...) I wish Write a Java application that uses the classes and methods above
Java application - JDBC
Java application  Seasons greetings, I successfully designed the Food festival application using the help rosenet team rendered but it is not exactly the specification i said.so i altered it.I thank rosenet team for their timely
Java application help!
Java application help!  In Deep Water Associates operates a business... (based on the fill-up time) for a pool. Write an application that prompts the user...-up price. Save the application as Swimming.java. Parameter Fee for cleaning Pool
Java application Help?
Java application Help?  Write an application that can hold five doubles in an array. Display the doubles from first to last, and then display the doubles from last to first. Save the file as DblArray.java. Use the logic
deploy java application
deploy java application  how i will deploy an java applet in Apache Http Server in unix
java chat application
java chat application  Can u plz send me java code for Lan communicatino(chat
java chat application
java chat application  Can u plz send me java code for Lan communicatino(chat
java application - Applet
java application  codes in repetition and decision  codes in repition and decision
Java Spring Desktop application
Java Spring Desktop application  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe package desktopapplication2
online test application in java
Online Test Application Table Of Contents Introduction To Application Database Design Creating Data Access Object (DAO) Design Pattern Creating Views Writing Actions Mapping Application Admin Module User Module Download
java spring simple application
java spring simple application  hai I have design a simple application in this I always found class not found exception. I am sendig code as follows please resolve this and send me.my directory structure is as follows Project
java application - JDBC
java application  Hi team rosenet, I ve used the ideas you gave and created an application.I need to do a modification to this code... main(String[] args) { // TODO code application logic here
deploy application - Java Beginners
deploy application  i want to deploy to tom cat server a web application using a eclips IDE. i already start the server but haven't no idea how to create the the war file using eclips. i pleasure if any one can help me. alsp
Java Bouncing Application
Java Bouncing Application  Hi I'm using Eclipse ide to add more implementation to this simple bouncing program. I'm having trouble implementing the following: -adding functionality of buttons and having color chooser -able
online test application in java
online test application in java  Can questions come in html file... radiobuttons in our application, you can take textarea, textfield etc. Here we have created... the following link: http://www.roseindia.net/jsp/online-quiz-application-jsp.shtml
Java swimming application
Java swimming application  In deep water associates operate a business that offers a variety of services to customers who own swimming pools, including cleaning and filling pools. Create pool class that calculates the price
java application/applet - Java Beginners
java application/applet  In this project, the student has to develop and submit a program for a Java application / applet which contains a set of GUI components as detailed below. 1. The Java applet page/application models
convert java Application to Java Applet
convert java Application to Java Applet  hi every Java Master or Java Professional , my Name Is Vincent i'm java beginner can i ask a question regarding for Java application convert to Java Applet. below her is my sample
convert java Application to Java Applet
convert java Application to Java Applet  hi every Java Master or Java Professional , my Name Is Vincent i'm java beginner can i ask a question regarding for Java application convert to Java Applet. below her is my sample
Java Application change to java applet
Java Application change to java applet   Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet hope every Masters can helping thank . import java.util.*; import java.text.
java Application Convert to java Applet
java Application Convert to java Applet  Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet hope every Masters can helping thank . import java.util.*; import java.text.
run a java application - Java Beginners
run a java application  Hai Deepak, I ve set my environment...; CLASSPATH= C:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar; JAVA_HOME=C:\Program Files\Java; path=C:\Program Files\Java\jdk1.6.0_06\bin; My
current application cursor - Java Beginners
current application cursor  Hi all, I want to design one tool for that i need to find out the application in which is running among other application.(if currently three application is running means i want to find out
Sms to mobile using java application
Sms to mobile using java application  Hi, i want to send sms to mobile using java application. But i dont have any idea for this procees. So kindly suggest me any ideas. regards vijayalakshmi
java hello and timer alert application
java hello and timer alert application  Hi, Please help me create a simple Java application that can display "Hello world" and current Time alert on mobile device screen using mobile screen emulator. Regards

Ads