Assignment 2
Assignment 2
Q1) PART B:
import java.util.Scanner;
Scanner a = new Scanner(System.in);
System.out.println("Enter an integer: ");
int b = a.nextInt();
Q1) PART C:
import java.util.Scanner;
Scanner input = new Scanner(System.in);
Int value = input.nextInt();
Q1) PART D:
System.out.println("This is a Java Program ");
Q1) PART E:
System.out.println("This is a Java \nProgram ");
Q1) PART F:
System.out.printf("%s\n%s",”This is java”,”program”);
Q1) PART G:
if ( number != 7 )
System.out.println( "The variable number is not equal to 7." );
Q2) PART A:
No error identified.
Q2) PART B:
Greater than sign (>) comes before is equal to sign (=).
if ( c >= 7 )
System.out.println( "c is equal to or greater than 7" );
Q3) PART A:
x=2
Q3) PART B:
Value of 2+2 is 4
Q3) PART C:
x=
Q3) PART D:
5=5
Q4)
a) p = i + j + k + 7;
d) value = input.nextInt();
Q5)
y=a *x*x*x+7;
Q6) PART A:
- and + operations are performed first but /, % and * have same precedence.
x =7 + 3 * 6 / 2 – 1 = 15
Q6) PART B:
- and + operations are performed first but /, % and * have same precedence.
x=2%2+2*2-2/2=3
Q6) PART C:
- and + operations are performed first but /, % and * have same precedence.
x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) ) = 324
Q7) PART A:
System.out.print("1 2 3 4");
Q7) PART B:
System.out.print(" 1 ");
System.out.print(" 2");
System.out.print(" 3 ");
System.out.printf(" 4");
Q7) PART C:
System.out.println(" 1 2 3 4");
Q8)
Scanner a=new Scanner(System.in);
System.out.print("Enter Any Two Intergers: ");
int num1=a.nextInt();
int num2=a.nextInt();
int num3=(num1+num2);
int num4=(num1-num2);
int num5=(num1*num2);
float num6=(num1/num2);
System.out.println("Addition of two integers: "+num3);
System.out.println("Difference of two integers: "+num4);
System.out.println("Product of two integers: "+num5);
System.out.printf("Quotient of two integers: %.2f",num6);
Q9)
System.out.print(" ********** *** * *\n");
System.out.print(" * * * * *** * *\n");
System.out.print(" * * * * ***** * *\n");
System.out.print(" * * * * * * *\n");
System.out.print(" * * * * * * * \n");
System.out.print(" * * * * * * *\n");
System.out.print(" * * * * * * *\n");
System.out.print(" * * * * * * *\n");
System.out.print(" * * * * * * *\n");
System.out.print(" ********** *** * *\n");
Q10)
*
**
***
****
*****
Q11)
*
***
*****
****
**
Q12)
***************
Q13)
****
*****
******
Q14)
*
***
*****