Incompatible Types / Void Cannot Be Converted To Int
Jul 29, 2014
package input;
import javax.swing.JOptionPane;
public class Input {
public static void main(String[] args) {
int user;
user = JOptionPane.showMessageDialog(null, "Enter Your Age""); ERROR IS HERE
if(user <= 18) {
JOptionPane.showMessageDialog(null, "User is legit");
} else {
JOptionPane.showMessageDialog(null, "User is not legit");
}
}
}
I'm getting this error message :
incompatible types: void cannot be converted to int
I have coded three classes ,1 class containing the Main method. I have declared three private data fields in Staff class and two data fields in Address class. The problem is that I am assigning String type data field from the Staff and Address Class through the public set methods to String type array in a public void method in the Main class.
public static void main(String[] args){ // TODO code application logic here System.out.println("-------------------------------------------------"); System.out.println("Press 1 - 6 To Perform Any One Following Action "); System.out.println("1. Insert New Contact "); System.out.println("2. Delete Contact By Name "); System.out.println("3. Replace Info From Contact "); System.out.println("4. Search Contact By Name "); System.out.println("5. Show All Contacts "); System.out.println("6. Exit Program ");
int a, b, sum; System.out.print("the sum is"); Scanner in = new Scanner(System.in); a = in.nextInt(); b = in.nextInt(); Sum = a + b; System.out.println("the sum us" + sum);
in "sum = a+b" its says "incompatible types: int cannot be converted to boolean" I dont understand why
What the program must do is to parse the string-declared two-dimensional array for the program to compute the student's scores in their quizzes, but I'm having difficulty in anything with Parsing so I don't know what will be the appropriate codes.
Error: incompatible types: String[][] cannot be converted to int[][]
import java.io.*; public class Quiz3{ public static void main(String[]args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String [][]StudQuiz = new String [5][4];
[Code] ....
How am I able to compute the average of the score if the data that is needed to be computed is in the string-declared array?
I have a method that receives an array of integers and saves the ID of the user inside the array of integers and I keep getting the error: "int[] cannot be converted to int".Here is the code:
public boolean Borrow (String TitleOrAuthor,int id){ int count = 0; int b1 = 0; int BookCount [] = new int [b1]; for (int i=0;i<Bcount;i++){ if(Booklist[i].getTitle().equals(TitleOrAuthor)) for(int j=0;j<b1;j++){ BookCount [j]= Booklist[i].getCopies(); BookCount [j]= id; b1++;
I have created a java file and coverted it into exe file.. that exe file can be run directly by clicking the icon.... i dont need this, i want to install this java exe file and then use it.. is there any possible way?
I am trying to write a password checker program and thats the error i get. (the final error!) but this one i dont know how to fix. here is my code.
/* Text Text text */
import java.util.Scanner; // Imports the Scanner class to get Keyboard Inputs class PriceRichardChapter5Test { public static void main (String [] args) { String Password; // Creates the Password variable
I don't understand how i'm supposed to define a variable when the user has to type it into the program so it can be converted. This program i'm working on is supposed to convert from meters to feet (meter = feet * 0.305) but the user has to type in the meters they want converted. how do i solve the problem that keeps coming up that says "variable meter symbol cant be found" ? I keep trying different lines to no avail
public class Lab2 { public static void main(String[] args) { double feet = meter * 0.305; double meter = feet/0.305; System.out.println("Enter in feet for conversion to meters"); meter = meter * 0.305;
I am working on a project that just calculates simple interest based upon a principal and a percent interest rate written as .xxxx from user.
I need the Loan amount and the final interest calculation to show up as a currency with commas in appropriate areas, the Rate to be expressed as X.xxx% instead of .xxxx
I keep getting this error when I compile:
C:JavaInterestCalculator.java:46: error: incompatible types: String cannot be converted to double principal = formatter.format(principal); ^ C:JavaInterestCalculator.java:49: error: incompatible types: String cannot be converted to double rate = formatter.format(rate); ^ C:JavaInterestCalculator.java:52: error: incompatible types: String cannot be converted to double totalInterest = formatter.format(totalInterest); ^ 3 errors
Tool completed with exit code 1
And here is my code
import java.util.Scanner; import java.text.NumberFormat; import java.text.DecimalFormat; // class declaration public class InterestCalculator { // main method declaration
I know void means it doesn't return anything but to me when I think it doesn't return anything it just does equations and other things. So why can you use this? Or is Void like returning input such as a Scanner?
I am trying to make a custom texture system for a block in Minecraft, I am not too advanced with Java and am not sure how to make this work the way I want it to.
Java Code:
/** The list of the types of step blocks. */ public static final String[] blockStepTypes = new String[] {"stone", "sand", "wood", "cobble", "brick", "smoothStoneBrick", "netherBrick", "quartz"}; private Icon missing; private Icon icon1; /** * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata */
[code]....
Alright, so basically I figured I could just tell the code to see if the block is made out of Stone, then to set the texture to Stone, or if it's made out of Sand, then set it to Sand.What I usually get is Eclipse telling me to "insert '!= null' check", "insert '!= null' check", and then just error out saying "Opperator != is undefined for the argument type(s) boolean null"
I have a program that I have created from scratch called Product and I also created a Tester program to test my theory. The only problem that I have is that I am getting an error with this statement System.out.printf statement. The statement needs to print out "Program [name = HP ENVY x360 TouchSmart, price = $xxxxxx". The error states that "The method printf(String, Object...) in the PrintStream is not applicable for the arguments (String, String, void).
Which tells me that it is referencing back to the class file where I have
public void applyDiscount(double percent) { percent = price - (price * percent); //establishing the discount }
The lines of code in my tester file are (partly displayed)
String formatString = "Product[name = %s, price = %.2f]"; System.out.printf(formatString, product.getName(), product.getPrice()) //user input the discount amount System.out.println("Enter discount percentage [0 - 100]: %.2f "); double discount = user_input.nextDouble(); System.out.printf(formatString, product.getName(), product.applyDiscount(discount)); //This is the line giving me an error. }
I want to have parameters that I use the "void" for, in other words it doesn't return anything.
class code { void go() { int TestStuff t = new TestStuff(); t.takeTwo(12,34) } void takeTwo (int x, int y) { int z = x + y; System.out.println("Total is:" + z); } }