Why float f = 10d will cause the compiler error/ and why int and double did not cause any compiler error ?
public class Main {
public static void main(String[] args) {
// write your code here
char c = 38;
int i = 'a';
double d = 10f;
double d2 = 10;
float f = 10d;
System.out.println(a + b);
}
}Float (f) a 32 bit precision floating data type whereas double (d) is a 64 bit precision floating data type. In simpler terms, double can store a larger range of values as compared to float. Thus the statement float f = 10d will result in a compilation error as we are trying to convert a larger data type to a smaller data type.
Why float f = 10d will cause the compiler error/ and why int and double did...
Write the output of the two codes below, unless there is a compiler error or a runtime error. In those cases, write CE or RE, respectively, and explain why those errors occur. If the code produces an infinite loop, write “LE: infinite loop”. public class ForLoopsDemo{ public static void main(String[] args){ int x = 4; fint x = 4; for( int i = 0; i < x; i++ ){ } } for( int j = 0; j < 2*i+1; j++)}...
FIX THE FOLLOWING JAVA CODE
public class Errors public static main(String[] args) { float sum int a = 27.5, b = 72.99; suma(a, b); System.out.println("Suma = %7:3b", sum); } //end main public static suma(float a, double b) { double suma suma = a + b; } }//end class
Identify a logical error in the following code and fix it. public class test1 { public static void main(String[] args){ int total; float avg; int a, b, c; a=10; b=5; c=2; total=a+b+c; avg=total/3; System.out.println("Average: "+avg); } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...
Java 1. Can you explain it how it will be printed step by step? Thanks!! What is printed by the following? for (int i=1; i<4; i++) { for (char c=’a’; c<=’c’; c++) { if (i%2==0) { i++; System.out.println(i + " " + c); } else { c++; System.out.println(c + " " + i); } } } 2. Is there a compiler error in this code? If so, what is it? If not, what’s printed? Is there a compiler error in...
Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...
Question 8 Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in a file named MyProgram.java. public class MYProgram { public static void main( String [] args ) { int [] arrayOfIntegers = { 15, 20, 30 50, 60 }; for( int i = 0; i <= arrayOfIntegers.length(); i++ ) { System.out.println( "Hello" + i * 2 ) int i = 100 * arrayOfIntegers[ i ]; doSomething( i ); } } Public static void DoSomething( )...
What display is produced by the execution of this JAVA program if we make the following call f(0,0). Please explain your answer public class function { static void f(int x){ System.out.println(1); } static void f(double x){ System.out.println(2); } static void f(char x){ System.out.println(3); } static void f(long x){ System.out.println(4); } public static void main(String[] args) { } }
What are the first five lines printed from this code and why? public class LoopQ { public static void main(String[] args) { for(char c = 'A'; c < 'Z'; c++) { for(int i = 0; i < 2; i++) { System.out.println("seat "+c+i); } } } }
COMPILER ERROR PLS HELP CAPITALIZE FIRST LETTER OF EACH WORD IN STRING IN JAVA public class Main { /** * Iterate through each line of input. */ public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line; while ((line = in.readLine()) != null) { line = Character.toUpperCase(line.charAt(0)) + line.subtring(1) + (" "); System.out.println(line); } } }
Java. What is the output of this code? Ace.java public class Ace { private double a; public Ace ( double x) { a = x; } public void multiply (double f) { a *= x; } public String toString () { return String.format ("%.3f", x); AceDem.java public class AceDemo { public static void main(String args[]) { Ace card = new Ace (2.133); card.multiply (.5); System.out.println (card); } }