Question

the two codes have an error and I can’t figure out where. First one public class...

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] + “ is the number” + (i+1) + “letter in the alphabet “);

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans1:

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.out.println(alphabet.charAt(k)+" is the number "+j+"letter in the alphabet"); //this line contains error.

Error1: System.ou should be System.out and

Error2: +j"letter in the alphabet should be +j+"letter in the alphabet

k++;

j++;

i--;

}

  

}

}

Ans 2:

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] + " is the number" + (i+1) + "letter in the alphabet ");

}
The above mentioned code is now rectified.

Add a comment
Answer #2
Add you answer here...
Add a comment
Know the answer?
Add Answer to:
the two codes have an error and I can’t figure out where. First one public class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is the output for the following program codes? a) [ 0.5 Mark ] class A...

    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 {...

  • Write the output of the two codes below, unless there is a compiler error or a...

    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++)}...

  • public class Test { private static int i =0; private static int j =0; public static...

    public class Test { private static int i =0; private static int j =0; public static void main(String[] args) { int i = 2; int k = 3; { int j =3; System.out.println("i + j is : " + i + j); } k = i + j; System.out.println("K is " + k ); System.out.println("K is " + j); } } why is the output i + j = 23 K =2 K =0 Please explain a step by step...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • What are the first five lines printed from this code and why? public class LoopQ {...

    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); } } } }

  • Identify and correct the error in the following codes, and state what type of error you...

    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;

  • Help with a question in Java: What is the output from the following program? public class...

    Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }

  • I'm trying to find out what is wrong with my code? package DriverClass; public class DriveClass...

    I'm trying to find out what is wrong with my code? package DriverClass; public class DriveClass { public static void main(String[] args) { int a[] = {3, 2, 5, 6, 1}; InsertionSortClass insertion = new InsertionSortClass(); System.out.print("The original list : "); System.out.println(); insertion.printArray(a); System.out.println(); System.out.println("The list after insertionSort : "); System.out.println(); insertion.insertionSort(a); } } package DriverClass; public interface SortADTInterface { public void insertionSort(int arr[]); public void printArray(int arr[]); } package DriverClass; public class InsertionSortClass implements SortADTInterface{ public void insertionSort(int[] arr)...

  • please evaluate the following code. this is JAVA a. class Car { public int i =...

    please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT