Exersice on Pseudocode In Java
In this lecture i am going to interact with earlier concepts that we have done. That concepts will make sure about what we have learnt and understand.
Some Exersice on Pseudocode to improve our basic understanding :
1. 2*4/2-8/4+2-11*4
2. String Name="Hello World";
char ch=Name.charAt(1);
int num=10;
int res=Num+ch;
char ch2=(char)res;
System.out.println(ch2);
3. int a=10;
int b=20;
int c=30;
int d=b/a+c/a;
int e=d+1;
int g=10;
int f=g+e;
System.out.println(e&f);
4. Enter a number then double it then add 2 and then perform & operation with 10.
5. Write a program to find:
(a) Perimeter of a cube
(b) Area of a cube
(c) Area of traingle
(d) Area of Circle
(e) Perimeter of a circle
6. Solve This
int b=4;
int c=2;
int a=1;
(b^2-4ac)/2a*4ac^2/2b
7. Solve This:
int a=0;
a++;
int b=a++;
b++;
--b;
++b;
System.out.println(b);
8. Find the result o the following:
(a) 1&0|1&0|1|1&0
9. Write a program to make a format like an email :
Hello mam/Sir,
This is to inform you that you are the part of our team now every problem will be seek as our problem
Thanks and regards
(Your name) Click Here for Next Page>>
package javaassignment;
public class Javaassignment {
public static void main(String[] args) {
// question number : 1
int expression = 2*4/2-8/4+2-11*4;
/*
precdence of '/ and *' > '+ and -'
Associativity is Left to right
2*4/2-8/4+2-11*4
8/2-8/4+2-11*4
4-2+2-44
4-44
-40
*/
System.out.println(expression);
// question number 2:
String Name = "Hello world";
/*
H E L L O _ W O R L D
0 1 2 3 4 5 6 7 8 9 10
length = 11
'a' = 97
'b' = 98
'e' = 101
*/
char ch1 = Name.charAt(1); // 'e'
int value = 10;
int value2 = ch1+value; // integer = char + integer = adding value = 111
char ch2 = (char)value2;
// a b c d e f g h i j k l m n o p
// 10 -- 'o' == 111
System.out.println(ch2);
// question number 3:
/*int d = 5;
int e = d+1; // 6
int f = 2+e; //2+6 ==8 i take value of is 'g' === 2
*/
int e = 6;
int f = 8;
/*
6 = (2)^2 + (2)^1 = 100 + 10 = 0110
8 = (2)^3 = 1000
0110
1000
----
0000 == '0'
*/
System.out.println(e&f);
// question 4th:
int a = 4;
int b = 2*a;
/*
8 = (2)^3 = 1000
10 = (2)^3+(2)^1 = 1000+10 = 1010
1000
1010
----
1000 = "8"
*/
System.out.println(b&10);
// question number 8:
int bit = 1&0|1&0|1|1&0;
/*
precdence = &>|
Associativity = L to R
1&0|1&0|1|1&0
0|0|1|0
0|1|0
1
*/
System.out.println(bit);
// question number 9:
String Emp = "Hello sir/ma'am \n \t\t I am glad to inform you that i have joined a new company an i am resigning from yours \nThanks and regards\nSachin Malhotra";
System.out.println(Emp);
}
}