English

Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output. import java.util.*; Class Program 4 { void main()

Advertisements
Advertisements

Question

Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output.

import java.util.*;
Class Program 4
{
      void main()
      {
          int n=0, p; Scanner sc = new Scanner (System.in);
          System.out.print(" Enter n : "); n == sc.nextInt();
          for(j=1; j<=10; j++)
          p=nxj;
          System.out.println (p + "x"+j+"= "+i);
      }
}
Code Writing
Advertisements

Solution

void main()
{
     int n=0, p,j; Scanner sc=new Scanner(System.in);
     System.out.print("Enter n:"); n=sc.nextInt();
     for(j=1; j<=10; j++)
     {
        p=n*j;
        System.out.println (n +"x"+j+"="+p);
     }
}

Multiplication Table

shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 48]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 1 Revision of Class 9 Syllabus
Exercises | Q 6. (iv) | Page 48
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×