Page 179 - ComputerScience_Class_11
P. 179
G. Identify the error in the given codes and rewrite the correct code:
1. import java.util.Scanner
class Bill
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
final int fixed = 100;
System.out.print("Enter units: ");
int units = sc.nextInt();
fixed = 150;
int total = units * 8 + fixed;
System.out.println("Bill = " + total)
}
}
Ans. import java.util.Scanner;
class Bill
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
final int fixed = 100;
System.out.print("Enter units: ");
int units = sc.nextInt();
int total = units * 8 + fixed;
System.out.println("Bill = " + total);
}
}
2. class Check
{
public static void main(String args[])
{
int a = 4, b = 6, c = 7;
IF ((a < b) && !(b < c) || (c = c))
System.out.println("True");
else
System.out.println("False");
}
}
Ans. class Check
{
public static void main(String args[])
{
int a = 4, b = 6, c = 7;
if ((a < b) && !(b < c) || (c == c))
Variables and Expressions 177

