Computer Science, asked by aarbhalolagchhena, 9 months ago

Rewrite the following program after removing the errors, underlining each
corrections:
class My Class
{
int a, b;
void initialize( )
{
a=5;
b=6;
}
void show( )
{
System.out.println(a+ “ ”+ b);
}
static void main( )
{
My Class ob = new My Class( );
ob.initialize( );
show( ).ob;
}
}
3.Which among the following are invalid class name in Java? State with reasons.
1. Compound Interest
2. 1MyClass
3. MyClass$
4. Myclass#
5. My@Class
4. Identify the mistake in each of these lines and correct it:
a. int goto=5;
b. float a=12.3;
c. doubles b=15;
d. long b=1536458888397632;
e. String s= „Computer‟;
5.State with reasons why are the following variable names invalid:
a. for
b. book list
c. 2ndTerm
d. hash#
e. sick@always
6.What is the resultant data type of the following mathematical expression?
a+b*c-d
a. where a is int, b is int, c is float and d is float type
b. b. where a is float, b is long, c and d are of int type
c. where a is of double and b,c and d are of int type.
d. where a is char and b,c and d are of int type
e. e. where a, b, c and d are of int type, however the expression is slightly
modified as (a+b*c-d)/7.0
7. class Output1
{
static void main()
{
int a=5,b=6,c;
c=a+b%2;
b=a+2*c;
System.out.println(c);
System.out.println(b);
}
}
8. class Output2
{
static void main()
{
int a=12,b=13,c=6;
c+=a+b%2;
b-=a+2*c;
System.out.println(c);
System.out.println(b);
}
}
9. class Output3
{
static void main()
{
int a=12,b=13,c=0,d=1;
c+=a;
c+=b;
d*=a;
d*=b;
System.out.println(c);
System.out.println(d);
}
}
10. class Output4
{
static void main()
{
int a=12,b=13,c;
c=a++ + ++a/7 + b++;
System.out.println(a+“\t”+b+“\t”+c);
c=++a + a++/3 + ++b;
System.out.println(a+“\t”+b+“\t”+c);
8. class Output2
{
static void main()
{
int a=12,b=13,c=6;
c+=a+b%2;
b-=a+2*c;
System.out.println(c);
System.out.println(b);
}
}
9. class Output3
{
static void main()
{
int a=12,b=13,c=0,d=1;
c+=a;
c+=b;
d*=a;
d*=b;
System.out.println(c);
System.out.println(d);
}
}
10. class Output4
{
static void main()
{
int a=12,b=13,c;
c=a++ + ++a/7 + b++;
System.out.println(a+“\t”+b+“\t”+c);
c=++a + a++/3 + ++b;
System.out.println(a+“\t”+b+“\t”+c);
17.Why is an Object called an 'Instance' of a class? Explain.
18.Why is a class known as composite data type?
19.Write a statement to create an object 'Keyboard' of the class 'Computer'.
20.Refer a class structure as shown below:
class MySchool {
Name
Address
Principal's name
AcceptData();
PrintData();
}
With reference to the above class declaration, indicate whether the following
statements are True/False:
1. Acceptdata( ) is the characteristic of the class.
2.Address is behaviour of the class.
3.Acceptdata( ) and PrintData( ) are the common behaviour of the objects of class
'MySchool'.
4.Behaviours are the medium of inter-object communication.
5.Creating multiple objects of class 'MySchool' is not possible.
21.Write a program by using a class 'Picnic' without any data members but having
only functions as per the specifications given below:
class name : Picnic
void display1( ): To print venue, place and reporting time.
void display2( ): To print number of students, name of the teacher accompanying
and bus number.
Write a main class to create an object of the class 'Picnic' and call the functions
display1() and display
22.Distinguish between:
(a) Integer and floating constant
(b) Token and Identifier
(c) Character and String constant
(d) Character and Boolean literal
23.What do you understand by primitive data type? Give two examples.
24.Why is it necessary to define data type in Java programming?
Define the following with an example each:
(a) Implicit type conversion
(b) Explicit type conversion
25.Write a program to find and display the value of the given expressions:
(a) (x + 3) / 6 - (2x + 5) / 3; taking the value of x = 5
(b) a
2
+ b
2
+ c
2
/ abc; taking the values a=5,b=4,c=3
26.A person is paid ₹350 for each day he works and fined ₹30 for each day he
remains absent. Write a program to calculate and display his monthly income, if
he is present for 25 days and remains absent for 5 days.
26.In a competitive examination, there were 150 questions. One candidate got
80% correct and the other candidate 72% correct. Write a program to calculate
and display the correct answers each candidate got.
28.Write a program to find and display the percenta
(b) a number is updated from 7.5 to 7.2
29.The normal temperature of human body is 98.6°F. Write a program to convert
the temperature into degree Celsius and display the output.
Hint: c / 5 = f - 32 / 9
30.The angles of a quadrilateral are in the ratio 3:4:5:6. Write a program to find
and display all of its angles. [Hint: The sum of angles of a quadrilateral = 360°]

Answers

Answered by anindyaadhikari13
21

Question 2:-

Rewrite the following after removing the errors.

Answer:-

After correction, the program will be,

class My Class

{

int a, b;

void initialize( )

{

a=5;

b=6;

}

void show( )

{

System.out.println(a+ “ ”+ b);

}

static void main( )

{

My Class ob = new My Class( );

ob.initialize( );

ob.show( );

}

}

Question 3:-

Which among the following are invalid class name in Java? State with reasons.

Answer:-

Compound Interest is an invalid identifier as identifier name must not contain spaces.

1MyClass is an invalid identifier as identifier name must not start with a digit.

MyClass$ is a valid identifier.

Myclass# is an invalid identifier as identifier name must not contain special characters (except dollars and underscores)

My@Class is an invalid identifier as identifier name must not contain special characters (except dollars and underscores)

Question 4:-

Identify the mistake in each of these lines and correct it:

Answer:-

  1. int goto=5; Here, goto is a keyword. Identifier name must not be a keyword. Replace it:- int go=5;
  2. float a=12.3; Write f at the end:- float a=12.3f;
  3. doubles b=15; There is no keyword like doubles. Write double there:- double b=15.
  4. long b=1536458888397632; Write l after this:- long b=1536458888397632L;
  5. String s=,,Computer":- Write this:- String s="Computer "

Question 5:-

State with reasons why are the following variable names invalid:

  1. for is an invalid variable name as it is a keyword and variable names must not be a keyword.
  2. book list is an invalid variable as it contains spaces.
  3. 2ndTerm is an invalid variable as it starts with a digit.
  4. hash# is an invalid variable as it contains special characters.
  5. sick@always is an invalid variable as it contains special characters.

Question 6:-

Write the resultant data type of the following.

  1. float.
  2. long.
  3. double.
  4. int.
  5. double.

Question 7:-

a=5, b=6

c=a+b%2=5+6%2=5+0=5

b=a+2*c=5+2*5=5+10=15

Output:-

5

15

Question 8:-

a=12,b=13 and c=6

c+=a+b%2

>> c=5+12+13%2=17+1=18

b-=a+2*c

>> b=13-(12+2*18)

>> b=13-(48)

>> b=-35

Output:-

18

-35

Question 9:-

Here, a=12,b=13,c=0,d=1

c+=a >> c=12

c+=b >> c=12+13=25

d*=a >> d=12

d*=b >> d=12*13=156

Output:-

25

156

Question 10:-

c=a++ + ++a/7+b++=12+14/7+13=27

Now, a=14 ,b=14

Now, output:-14 14 27

Again,

c=++a + a++/3 + ++b =15+15/3+15=35

Now, a=16, b=15

Output:- 16 15 35

Output:-

14 14 27

16 15 35

Question 17:-

Since an object possesses an instant variables and member methods defined within the class, hence it is called the instance of a class.

Question 18:-

A class is a tool to create user defined data types. The class name becomes the data type for instances used in the program. It is such a data type that includes various predefined data types within it. Hence, the class is said to be a composite data type.

Question 19:-

Computer Keyboard=new Computer();

Question 20:-

  1. False.
  2. False.
  3. True.
  4. True.
  5. False.

Question 21:-

class Picnic

{

void display1()

{

System.out.println("Venue: Write venue here. ");

System.out.println("Place: Write Place here. ");

System.out.print("Reporting Time: 9am.");

}

void display2()

{

System.out.println("Number of students: 50");

System.out.println("Name of teacher: Write name.");

System.out.println("Bus Number: 5");

}

public static void main()

{

Picnic x=new Picnic();

x.display1();

x.display2();

}

}

Question 25(b):-

class X

{

public static void main()

{

int a=5,b=4,c=3;

double x=(a*a+b*b+c*c)/(a*b*c);

System.out.println(x);

}

}

Question 26:-

class x

{

public static void main()

{

int s=25*350-5*30;

System.out.println("Salary: "+s);

}

}

Question 26(second one) :-

class X

{

public static void main()

{

int q=150;

int c1=(int)(80/100.0*q),c2=(int)(72/100.0*q);

System.out.println("Candidate 1: "+c1);

System.out.println("Candidate 2: "+c2);

}

}

Question 28:-

class X

{

public static void main()

{

int a=80,b=90;

int c=b-a;

double p=c/(double)a *100;

System.out.println("Increased by "+p+"%");

}

}

class Y

{

public static void main()

{

double a=7.5, b=7.2;

int c=a-b;

double p=c/a *100;

System.out.println("Decreased by "+p+"%");

}

}

Question 29:-

class x

{

public static void main()

{

double f=98.5;

double c=5*(f-32)/9.0;

System.out.println(c);

}

}

Question 30:-

class x

{

public static void main()

{

int a=3,b=4,c=5,d=6;

int s=a+b+c+d;

double x=360/(double)x;

double a1=a*x, a2=b*x, a3=c*x, a4=d*x;

System.out.println("First Angle: "+a1);

System.out.println("Second Angle: "+a2);

System.out.println("Third Angle: "+a3);

System.out.println("Fourth Angle: "+a4);

}

}

Attachments:
Answered by scoobydoobygamerz
0

Answer:

Idk

Explanation:

Did not understand ur question

Similar questions