Ass 1
Ass 1
Q2.) Complete the given program to create a simple calculator that performs addition and subtraction.
-> Declare an integer variable sum and assign the value of addition of a and b to it.
-> Declare another integer variable diff and assign the value of subtraction of a and b to it.
-> Output sum and diff to the console on separate lines with the same message as given in sample
output.
Q3.) Write a program which does the following:
-> Declare a string variable x.
-> Accept a text user input the name of the user - and store it in the variable x.
-> Output and print to the console "Hello" before the user defined name.
Q4.) What will be the output of this code, if the user enters Ram?
class Sample {
String sc = read.nextLine();
}
}
=It is not showing output not showing Error. Program continues its execution till close the program.
Q5.) What will be the output of this code, if the user enters
class Sample {
int a = read.nextInt();
int b = read.nextInt();
int c = a + 2;
int d = c + b;
System.out.println(d);
}
Q6.) Write a java program that uses the Scanner class to get userID, password, name and age from the
user input?