Incompatible Types For Fname
May 6, 2014
import java.util.Scanner;
class potatoes {
public static void main(String[] args){
Scanner user = new Scanner(System.in);
String fname;
fname = user.nextLine;
String newfname = fname.substring(0, 3);
System.out.println(newfname);
}
}
This bit of code isnt working, it has something to do with incompatible types for fname
View Replies
ADVERTISEMENT
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
unclosed string literal
View Replies
View Related
Mar 19, 2014
I am trying to write a program to calculate the monthly amount paid for a mortgage and the total amount but i keep getting this errors Attachment 5998
This is my program:
import static java.lang.Math.pow;
import java.io.*;
import java.util.*;
class MyInput
{ static private StringTokenizer stok;
static private BufferedReader br
= new BufferedReader(new InputStreamReader (System.in));
public static int readInt()
[code]....
View Replies
View Related
Mar 12, 2015
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
View Replies
View Related
Mar 4, 2015
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?
View Replies
View Related
Nov 23, 2014
import java.lang.Math;
import static java.lang.Math.random;
import java.util.Scanner;
public class LineofCoordinates
{
public static void main( String[] args, String x, String random, String exit, String y, String y2, String x2)
[Code] ....
View Replies
View Related
Jul 26, 2014
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 ");
[Code] ....
View Replies
View Related
Jan 24, 2015
I am using netbeans and have an error that reads "incompatible types: String cannot be converted to List<String>"
List<List<String>> fileDArr;
fileDArr = new ArrayList<>();
Scanner tempStringScanner;
try {
for (int i = 0; i < FileDirectory.length; i++) {
[code] .....
I don't understand why I am receiving the error. I thought that .next() returned a String?
View Replies
View Related
Apr 10, 2014
I am new in java.. I am having a problem when doing merge sort. This is my coding...
Java Code:
import java.util.*;
public class Person
{
public static void main(String[] args)
{
String[] list = {"
[Code] ....
the error is incompatible type at 'sorted = merge(left,right);'
View Replies
View Related
Jan 22, 2015
Why the following is happening.
For the below code, when I execute it, it prints
Short method 10 //result 1
Sub class short method 10 //result 2
Which is as expected but if I comment out line 3, then it prints
Integer method 10 //result 3
Integer method 10 //result 4
I can understand result 3 is because of an upcast from short to int, since FunWithOverloading will not have a overloaded method with short now. However, what is happening with result 4? Shouldn't it call methodA of the subclass with the argument type short? If its because I have declared the reference variable, derived, of the type FunWithOverloading, then how come the first result correctly picks the overloaded method of the sub class?
class FunWithOverloading{
void methodA(int x){System.out.println("Integer method " + x);}
void methodA(short x){System.out.println("Short method " + x);} //line 3
} class OverloadedSubClass extends FunWithOverloading{
void methodA(short x){System.out.println("Sub class short method " + x);}
[Code] ....
View Replies
View Related
Sep 18, 2014
For basic arrays, we can directly combine declaration and initialization as E.g: int[] num= new int[2]
But can we do this do for forming class object arrays? like
class stu
{
.....
}
stu[] s=new stu[2]
????
View Replies
View Related
Mar 17, 2014
how objects relate to classes and how you can create and re-use object types.on that point, but this has me baffled. I most certainly do not have a firm grasp yet on passing things to and from methods that just makes my head hurt. SO anyway I tried out one of the code examples:
/* ElectricGuitar.java */
class ElectricGuitar {
String brand;
int numOfPickups;
boolean rockStarUsesIt;
[code]...
But I just realized this thing has no main method and only one class defined.....so I guess I just tried to compile.
View Replies
View Related
Apr 1, 2014
I am trying to understand the concept of Generics in java. In the introduction to Generic Types, this example is given:
Java Code: public class Box {
private Object object;
public void set(Object object) { this.object = object; }
public Object get() { return object; }
} mh_sh_highlight_all('java'); "Since
Since its methods accept or return an Object, you are free to pass in whatever you want, provided that it is not one of the primitive types." - I understand this.But then it has been changed to a generic class:
Java Code: /**
* Generic version of the Box class.
* @param <T> the type of the value being boxed
*/
public class Box<T> {
// T stands for "Type"
private T t;
public void set(T t) { this.t = t; }
public T get() { return t; }
} mh_sh_highlight_all('java'); "
As you can see, all occurrences of Object are replaced by T. A type variable can be any non-primitive type you specify: any class type, any interface type, any array type, or even another type variable."We can use any type in place of an Object, because Object is a superclass of all classes. But T (or any other class) is not a superclass of all classes. So how do we justify any class being used in place of a random T or any other class?
View Replies
View Related
Feb 23, 2015
I've got a question to ask.
public class AutoBoxingExample {
public void add(Integer intVal){
System.out.println("Wrapper");
}
public void add(int value){
System.out.println("Primitive");
}
public static void main(String[] args) {
AutoBoxingExample auto = new AutoBoxingExample();
auto.add(12);
}
}
The output is "Wrapper". What would be the reason behind it?
View Replies
View Related
Mar 14, 2014
GoodEmployee is defined who has ALL the following properties:
He should be married.
He should have 2 or less than 2 children.
His middle name should start with "k" but not end with "e"
The last name should have more than 4 characters
The character "a" should appear in the last name at least two times.
The name of one of his children should be "Raja"
Write a method:
boolean isGoodEmployee( boolean isMarried, int noOfChild , String middleName , String lastName , String[] childNames);
isMarried true if the employee is married.
noOfChild the number of children of the employee.
middleName the middle name of the employee
lastName the last name of the employee.
childNames the array of the names of the children of the employee
View Replies
View Related
Feb 13, 2015
This code works
public class RedShapeDecorator extends ShapeDecorator {
public RedShapeDecorator(Shape decoratedShape) {
super(decoratedShape);
}
Below results in an error
public class RedShapeDecorator extends ShapeDecorator {
protected Shape decoratedShape;
public RedShapeDecorator(Shape decoratedShape) {
this. decoratedShape=decoratedShape;
}
So I am guessing that if you extend class, you should use super to pass objects?
View Replies
View Related
Mar 17, 2014
Attempting to write a custom comparator for sorting songs, but I keep getting errors saying that the types cannot be resolved.
Java Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.*;
public class SongCollection {
[Code] .....
View Replies
View Related
Jun 3, 2014
public static void main(String[] args) {
System.out.println("VALUE Types");
int i = 5;
int j = 11;
System.out.println("i = " + i + ", j = " + j);
[Code] ....
Questions based on the code:
1. Identify all of the actual parameters in the code provided.
(Is it just i, j iArray and jArray)???
2. Identify all of the formal parameters in the code provided.
3. What is displayed in the third println statement?
i = 11, j = 2001
4. What is displayed in the fifth println statement?
iArray = 6 7 2001 9 10, jArray = 6 7 2001 9 10
View Replies
View Related
Apr 16, 2014
Why is it necessary to implement the comparable interface for primitive types and not for classes such as Integer, String etc . . . ?
View Replies
View Related
Dec 8, 2014
I need to write a class that represents and image of RGB pixels. This class uses a two-dimensional array of object type that represents R,G and B values.
When I compile the class it completes successfully. However, when I try running a "tester" class , I'm encountering errors in a few methods. I've been trying it out for 2 days now, but unsuccessfully thus far..Those method are : rotating the image by 90 degrees clockwise (and vice versa , but I just use clockwise method 3 times for that) , shifting the image sideways, and shifting the image up/down..
I've attached the whole source code for the class , and the list of errors I get when I try to run my tester. URL...
View Replies
View Related
Jun 26, 2014
I am looking at a snippet of code in my "learning Java 4th edition" by Orielly and there is a small snipped of code which says:
Java Code: Date date = new Date();
List list = new ArrayList();
list.add( date );
..
Date firstElement = (Date)list.get(0); // Is the cast correct? Maybe. mh_sh_highlight_all('java'); so I am typing the same thing in my compiler in a small Driver class and for some reason I have an error and Im dumbfounded...
View Replies
View Related
Nov 21, 2014
What class does method Planet.values() in the code below belong to? I thought it belongs to java.lang.Enum but when I could not see it in Java API 7.
package enumeration;
public class EnumTest {
public static void main(String[] args) {
//Planet myPlanet = Planet.EARTH;
// Check arguments supplied
if (args.length != 1) {
System.err.println("Usage: java EnumTest <earth_weight>");
System.exit(-1);
[code]....
View Replies
View Related
Sep 23, 2014
Here is my code:
import java.util.*;public class DebugSix {
public static void main(String[] args) {
ArrayList<String>products = new ArrayList();
products.add("shampoo");
products.add("moisturizer");
products.add("conditioner");
Collections.sort(products);
[Code] ....
I am using netbeans and getting errors for display(); and size(); it is telling me the errors are :
for the display error, "method display in class DebugSix cannot be applied to given types;
display();" and for the size() is : "cannot find symbol System.out.println("
The size of the list is " + size());"
View Replies
View Related
Jun 30, 2014
how many types of inputting method in java?can you explain with examples?
View Replies
View Related
Apr 25, 2015
I would like to know that i am getting an error with the random. it is say bad operand types for binary operator ' +'
[/ Random generator = new Random(15) + 1];
View Replies
View Related
Jul 15, 2014
There is a sentence in JLS 7 which I can't figure it out. It says :
A cast from a type S to a parameterized type T is unchecked unless at least one of the following conditions holds:
-S <: T
-All of the type arguments (ยง4.5.1) of T are unbounded wildcards
-T <: S and S has no subtype X other than T where the type arguments of X are not contained in the type arguments of T.
Condition one and two I got it. But the number three is really bugging me. I write some code in order to try to understand it.
class G<X>{}
class D<T,U> extends G<T>{}
G<String> g = new G<>();
D<String, Integer> dd = (D<String, Integer>) g;
In Eclipse I got no warning but it shouldn't give one ?
Because g has others subtypes than D<String, Integer> (e.g. D<String, List> , D<String, G>)
Am I missing something about the contained type arguments ?
View Replies
View Related