0% found this document useful (0 votes)
52 views

Computer Programming: Java Exercise 1 Name: Pramit Ranjan Ray Reg No: 21BCT0060

This document contains 5 Java programming questions and their source code. Question 1 takes a name as input and prints it. Question 2 calculates the average of 3 numbers input. Question 3 performs arithmetic operations and prints results. Question 4 calculates perimeter and area of a circle given radius. Question 5 takes student details as input and prints them.

Uploaded by

Urjoshi Aich
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Computer Programming: Java Exercise 1 Name: Pramit Ranjan Ray Reg No: 21BCT0060

This document contains 5 Java programming questions and their source code. Question 1 takes a name as input and prints it. Question 2 calculates the average of 3 numbers input. Question 3 performs arithmetic operations and prints results. Question 4 calculates perimeter and area of a circle given radius. Question 5 takes student details as input and prints them.

Uploaded by

Urjoshi Aich
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Programming: Java

Exercise 1

Name: Pramit Ranjan Ray


Reg No: 21BCT0060

Question 1

Source Code:

import java.util.*;
public class Exercise1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String Name = sc.next();
System.out.println("Hello");
System.out.println(Name);
}

Output:

Question 2

Source Code:

import java.util.*;
public class Exercise1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int z = sc.nextInt();
double average = (x+y+z)/3.0;
System.out.println(average);
}
}

Output:

Question 3

Source Code:

import java.util.*;
public class Exercise1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = -5+8*6;
System.out.println(a);
a = (55+9)%9;
System.out.println(a);
a = 20+ -3*5/8;
System.out.println(a);
a = 5+15/3*2-8%3;
System.out.println(a);
}
}
Output:

Question 4

Source Code:

import java.util.*;
public class Exercise1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int radius = sc.nextInt();
double pi = 3.14;
double perimeter = 2*pi*radius;
double area = pi*radius*radius;
System.out.println(perimeter);
System.out.println(area);
}
}

Output:
Question 5

Source Code:

import java.util.*;
public class Exercise1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String Register_No = sc.next();
String Name = sc.next();
String Dept = sc.next();
int Age = sc.nextInt();
long Mobile_No = sc.nextLong();
double GPA = sc.nextDouble();
System.out.println("Registration No. "+Register_No);
System.out.println("Name: "+Name);
System.out.println("Department: "+Dept);
System.out.println("Mobile No. "+Mobile_No);
System.out.println("Age: "+Age);
System.out.println("GPA: "+GPA);
}
}

Output:

You might also like