Test 1: Java: Name Rohit Kumar Roll No. 1802452 CEC CGC Landran

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Test 1 : Java

Name =Rohit Kumar

Roll no. 1802452

CEC CGC landran

import java.util.Scanner;

public class javaFirstTestSuraj {

public static void main(String[] args) {

Scanner sc =new Scanner(System.in);

//1

/* int total=0;

System.out.println("enter the physics marks");

int phy=sc.nextInt();

System.out.println("enter the maths marks");

int math=sc.nextInt();

System.out.println("enter the s.science marks");

int s_sci=sc.nextInt();

System.out.println("enter the english marks");

int eng=sc.nextInt();

System.out.println("enter the hindi marks");

int hind=sc.nextInt();

total=(phy+math+s_sci+eng+hind)/5;

System.out.println("your total marks is :"+total+"%");

*/
//2

/* System.out.println("enter the first number");

int a=sc.nextInt();

System.out.println("enter the second number");

int b=sc.nextInt();

System.out.println("enter the third number");

int c=sc.nextInt();

int d=a+b+c;

System.out.println("the sum of three number is :"+d);

*/

//3

/* System.out.println("enter your name");

String s=sc.nextLine();

System.out.println("hello "+ s+" have a good day");

*/

//4

/* System.out.println("enter the kilometer");


int a=sc.nextInt();

int m=a*1000;

System.out.println(a+" kilometer is : "+ m +"meter");*/

//5

/* System.out.println("please enter an input");

if(sc.hasNextInt()){

System.out.println("Entered input is integer");

else if(sc.hasNext()){

String string = sc.nextLine();

if(string.length()>1){

System.out.println("Entered input is String");

else{

System.out.println("Entered input is Char");

}}*/

//6

/* float a=7/4*9/2 ;

System.out.println(a);

*/
//7

/* char a='b';

a=(char)(a+8);

System.out.println(a);

a=(char)(a-8);

System.out.println(a);*/

//8

/* System.out.println("enter the number");

int a=sc.nextInt();

int b=10;

if(a>b){

System.out.println("a is greater than to b by: "+ (a-b));}

else{

System.out.println("a is lessthan to b by: "+(b-a));

}*/

//9

/* System.out.println("enter the value of v");

int v=sc.nextInt();

System.out.println("enter the value of u ");

int u=sc.nextInt();

System.out.println("enter the value of a");

int a=sc.nextInt();

System.out.println("enter the value of s ");

int s=sc.nextInt();

float total=((v*v)-(u*u))/2*a*s;
System.out.println("(v^2-u^2)/2as= "+total);*/

//10

/* int x=7;

int a=7*49/7+35/7;

System.out.println(a);

//11

*/

/*System.out.println("enter the string");

String s=sc.nextLine();

String s1=s.toLowerCase();

System.out.println(s1);*/

//12

/* System.out.println("enter the string");

String s=sc.nextLine();

String s1= s.replaceAll(" ","_");

System.out.println(s1);

*/

//13

/* String letter="Dear <|name|>, Thanks a lot";

System.out.println(letter);

String s1=letter.replace("<|name|>","suraj");

System.out.println(s1);*/

//14

/* System.out.println("enter the string");

String s=sc.nextLine();

System.out.println(s.indexOf(" "));

System.out.println(s.indexOf(" "));*/
//15

/* String letter="dear Shivani,\n\t\t\tThis java Course is nice.\n \t\t\t\tthanks";

System.out.println(letter);*/

// 16

/* System.out.println("enter the math marks");

float a=sc.nextFloat();

System.out.println("enter the english marks");

float b=sc.nextFloat();

System.out.println("enter the science marks");

float c=sc.nextFloat();

float total=(a+b+c)/3;

if(a>33 && b>33 && c>33){

if(total>=40) {

System.out.println("you r pass");

else{

System.out.println("you r fail");

else{

System.out.println("you r fail");

*/
// 18.Write a Java program to find whether a year entered by the user is a leap year or not.

/* System.out.println("enter the year ");

int year=sc.nextInt();

if(year%4==0 && year%100!=0|| year%400==0){

System.out.println("leap year");

else{

System.out.println("not a leap year");

*/

// 19

/* int a=sc.nextInt();

for(int i=a;i>0;i--){

for(int j=0;j<i;j++){

System.out.print("*");

System.out.println();

}*/
//20

/*int a=8; int sum=0;

for(int i=1;i<=10;i++){

sum+=a*i;

System.out.println(sum);*/

// 21.Create an array of 5 floats and calculate their sum.

/* float []a={2.5f,1.5f,3.5f,4.5f,6.5f};

float sum=0;

for(float b:a){

sum=sum+b;

System.out.println(sum);*/

// 22.Write a program to find out whether a given integer is present in an array or not.

/* int a[]={1,2,3,4,5,6};

System.out.println("enter the integer to check");

int b=sc.nextInt();

boolean c=false;

for(int i=0;i<a.length;i++){

if (b==a[i]){

c=true;
break;

}}

if(c){

System.out.println("present");}

else{

System.out.println(" not present");

}*/

// 24.Create a Java program to add two matrices of size 2x3.

/* int rows = 2, columns = 3;

int[][] firstMatrix = { {2, 3, 4}, {5, 2, 3} };

int[][] secondMatrix = { {4, 5, 3}, {5, 6, 3} };

int[][] sum = new int[rows][columns];

for(int i = 0; i < rows; i++) {

for (int j = 0; j < columns; j++) {

sum[i][j] = firstMatrix[i][j] + secondMatrix[i][j];

System.out.println("Sum of two matrices is: ");

for(int[] row : sum) {

for (int column : row) {

System.out.print(column + " ");

}
System.out.println();

}*/

// 26 and both are same 27.Write a Java program to find the maximum element in a Java array.

/* int a[]={3,5,7,9,11};

int max=a[0];

for(int i=1;i<a.length;i++){

if(max<a[i]){

max=a[i];

System.out.println(max);*/

// 28.Write a Java program to find whether an array is sorted or not.

/* int a[]={2,1,4,3,5};

for(int i=0;i<a.length-1;i++){

if(a[i]>a[i+1]){

int temp =a[i];

a[i]=a[i+1];

a[i+1]=temp;

}}
for(int i=0;i<a.length;i++) {

System.out.println(a[i]);

*///29and both are same 25.Write a Java program to print the elements of an array in reverse order.

/* int a[]={1,2,3,45,5};

for(int i=a.length-1;i>=0;i--){

System.out.println(a[i]);

}*/

// 30.What can be done using one type of loop can also be done using the other two types of
loops - True or False.

//answer=True
//17

/*

System.out.println("Enter your income in Lakhs per annum");

float tax = 0;

float income = sc.nextFloat();

if(income<=2.5){

tax = tax + 0;

else if(income>2.5f && income <= 5f){

tax = tax + 0.05f * (income - 2.5f);

else if(income>5f && income <= 10.0f){

tax = tax + 0.05f * (5.0f - 2.5f);

tax = tax + 0.2f * (income - 5f);

else if(income>10.0f){

tax = tax + 0.05f * (5.0f - 2.5f);

tax = tax + 0.2f * (10.0f - 5f);

tax = tax + 0.3f * (income - 10.0f);

System.out.println("The total tax paid by the employee is: " + tax);*/

}}

23 answer *************

import java.util.Scanner;

class Main

public static void main(String args[])

{
int i;

System.out.println("Enter number of Physics Student");

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int[] a=new int[n];

double avg=0;

System.out.println("Enter marks");

for( i=0;i<n;i++)

a[i]=sc.nextInt();

for( i=0;i<n;i++)

avg=avg+a[i];

System.out.print("Average of (");

for(i=0;i<n-1;i++)

System.out.print(a[i]+",");

}
System.out.println(a[i]+") ="+avg/n);

You might also like