Lab 1
Lab 1
Getting Started
public class hello {
public static void main(String[] arg) {
System.out.println("Hello");
System.out.println("hi there");
}
}
Adding Two Integers
public class Add{
public static void main(String args[])
{
int x=6,y=7;
int sum=x+y;
System.out.println("x+ y ="+sum);
}
}
Write a java program that adds two integers taken from the user
import java.util.*;
public class Input {
public static void main(String args[])
{ int num1; double num2; String name; double sum;
Scanner in = new Scanner(System.in);
System.out.print("Enter an integer: ");
num1 = in.nextInt();
System.out.print("Enter a floating point number: ");
num2 = in.nextDouble();
System.out.print("Enter your name: ");
name = in.next();
System.out.println("Name:"+name);
System.out.println("Integer:"+num1);
System.out.println("Real:"+num2);
} }
Adding two integers taken from the user
import java.util.*;
public class add {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the first number:");
int x=in.nextInt();
System.out.print("Enter the second number:");
int y=in.nextInt();
int sum=x+y;
System.out.print(“x+y="+sum);
}}
What is the output of the following code
public class Operators {
public static void main(String[] args) {
int number = 5*3+6/3+9-3;
System.out.println(number);
int x = 7,y = 2;
System.out.println(x/y+"\t"+ x%2);
int i=2,j=3;
int f=++i * j--;
System.out.println(f);
}
}
What are the values of r and a ?
public class Relational {
public static void main(String[] args) {
int x = 8, y = 2;
boolean r = (15 == x + y);
System.out.println(r);
boolean a = ((x>5) && (y!=2)|| (y<= (x+y)));
System.out.println(a);
}
}