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++)}
System.out.print("#");
}
System.out.println();
}
public class ForLoopsDemo{
public static void main(String[] args)
{
int x = 4;
fint x = 4; // "fint" is not any Data Type of java and variable x
is already defined in method
for( int i = 0; i < x; i++ ){
} } //misplaced closing brace before the for statement (syntax
error)
for( int j = 0; j < 2*i+1; j++)} //opening brace is missed
(syntax error)
System.out.print("#");
}
System.out.println();
} // missing curly braces, to end a class without including the
closing curly brace will generate the error and this is syntax
error
The above program contain the Compiler Error(CE)
Compile-time errors are generally syntax or semantics errors. These error get detected by compiler and can get fixed at the time of code development.
When you run this program 18 error will occur
ERROR Result
Corrected Program:-
public class ForLoopsDemo{
public static void main(String[] args)
{
int x = 4;
for( int i = 0; i < x; i++ )
{
for( int j = 0; j < 2*i+1; j++)
{
System.out.print("#");
}
System.out.println();
}
}
}
output
#
###
#####
#######
Write the output of the two codes below, unless there is a compiler error or a...
java Use the classes given in the previous question and write the output tha t is generated when this program is run. You may write your answer as "Elaine 2 Jerry 1" or "Compiler Error" or "Runtime Error" If there is an error then explain why. public class Main{ public static void main(String args[]){ Object o = new Kramer(); ((George)(o)).method1(); ((Jerry)(o)). method1(); 0.method2(); public class George extends Elaine {! public void method1() { System.out.print("George 1 "); public class Jerry {...
Identify and correct the error in the following codes, and state what type of error you will get? public class Assignmet2{ public static void main(String []args){ int x=2; for(int year=1; year>=0; year--) for (int day=2; day!=3; year++) {if ( x>=1) System.out.println("Yes"); else System.out.println("No"); x--;} }} int[] grade = new int[20]; for(int counter=0; counter<=grade.length; i++) grade[counter]=20;
Here is everything I have on my codes, the compiler does not allow me to input my name, it will print out "Please enter your name: " but totally ignores it and does not allow me to input my name and just proceeds to my result of ID and Sale. Please help. I've bolded the part where it I should be able to input my name package salesperson; public class Salesperson { String Names; int ID; double Sales; // craeting...
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...
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 is the output for the following program codes? a) [ 0.5 Mark ] class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); }} class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); }} OUTPUT: b) [ 0.5 Mark ] class Parent { public void getBike(){ System.out.println("Suzuki Bike"); }} class Child extends Parent {...
// 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and //1 usability error. Identify them all. import java.util.scanner; //This program finds the average of three input values. public class Arithmeticx { public static void main( String [] args ) // declare variables double number1, number2, number3; // input data scanner in = newscanner( ); System.out.print( "Number 1? " ); System.out.print( "Number 2? " ); System.out.print( "Number 3? " ); number 1 = in.nextDouble; number...
the two codes have an error and I can’t figure out where. First one public class Program { public static void main(String[] args) { int i, j = 1, k = 0; String alphabet = "abcdefghijklmnopqrstuvwxyz"; i = alphabet.length(); while (i>0){ j=(i-(i-j)); System.ou.println(alphabet.charAt(k)+" is the number "+j"letter in the alphabet"); k++; j++; i--; } } } Second one char [] alphabet = {a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,a,r,s,t,u,v,w,x,y,z}; for (int i = 0; i < alphabet.length; i++) { System.out.println(alphabet[i] +...
Write a program that prints an imitation of the Composition II in Red, Blue, and Yellow created in 1930 by Piet Mondrian painting, illustrated below. Use character sequences such as @@a or: to indicate different colors and use - and| to form the black lines. with algorithm public class Solution - public static void main(String[] args) { for(int FI ;İ<-50;İ++){ for(int Hj<-50;jt+){ if(j-12) { System.out.print("! "); } else ifj>12 && і 39){ System.out.print("@ "); 3 else if(i--39)\ System.out.print( "-"); }...
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...