0% found this document useful (0 votes)
121 views10 pages

CSE 1007 - Java Programming

This document contains details of a Java programming assignment for the CSE 1007 course. It includes the student's name, registration number, faculty, and 8 programming questions with sample code and output for each question. The questions cover topics like 2D arrays, string manipulation, condition checking, and number base conversions.

Uploaded by

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

CSE 1007 - Java Programming

This document contains details of a Java programming assignment for the CSE 1007 course. It includes the student's name, registration number, faculty, and 8 programming questions with sample code and output for each question. The questions cover topics like 2D arrays, string manipulation, condition checking, and number base conversions.

Uploaded by

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

CSE 1007 – Java Programming

Name – Naman Sood


Registration Number – 18BCI0168
Slot - L53+L54
Faculty – Prof. JABANJALIN HILDA J
LAB Assignment – 3
Q1.
Code
import java.io.*;
import java.util.*;
public class jagged
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // no of semesters done
sc.nextLine();
int[][] marks = new int[n][];
for (int i = 0;i<n;i++)
{
String[] sarr = sc.nextLine().split(" ");
int[] sub = new int[sarr.length];

for (int j=0;j<sarr.length;j++)


{
sub[j] = Integer.parseInt(sarr[j]);
}
marks[i] = sub;
}
int[] res = processMarks(marks);
System.out.println("Passed : " + res[0] + "\nFailed : " +res[1]);
}

public static int[] processMarks(int[][] marks)


{
int passed = 0;
int failed = 0;
for (int[] a : marks)
{
for (int i : a)
{
if (i >= 40)
{
passed += 1;
}
else{
failed += 1;
}
}
}
return new int[]{passed, failed};
}
}
Output
Q2.
Code
import java.util.Scanner;

public class vit_count


{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
//assuming sentence only has alphabets
s = s.replace("VIT", "1");
int count = 0;
for (int i = 0; i < s.length(); i++)
{
if (s.charAt(i) == '1')
{
count += 1;
}
}
String res = (count == 0) ? "No such word in the sentence" : "count
: " + count;
System.out.println(res);
}
}

Output
Q3.
Code
import java.util.Scanner;

public class scope {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] regNos = sc.nextLine().split(" "); //inputting all reg nos
in a single line seperated by a space
int scopeCount = 0;
int senseCount = 0;
for (String s : regNos) {
if (s.contains("BCE")) {
scopeCount += 1;
} else if (s.contains("BEC")) {
senseCount += 1;
}
}
if (senseCount == 0 && scopeCount == 0) {
System.out.println("There are no students from SCOPE and SENSE
school");
} else {
System.out.println("SCOPE : " + scopeCount + "\nSENSE : " +
senseCount);
}
}
}

Output
Q4.
Code
import java.util.Scanner;

public class finding_name {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] names = sc.nextLine().split(","); //inputting all names in
a single line seperated by a comma
String searchName = sc.nextLine(); //name to be searched

for (String name : names) {


if (name.contains(searchName)) {
System.out.println("Name Found");
return;
}
}
System.out.println("Name not found");
}
}
Output
Q5.
Code
import java.util.Scanner;

public class username_password


{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String username = sc.nextLine();


String password = sc.nextLine();

//assuming username and password is atleast of three letters


int n = username.length();
boolean weak = false;
for (int i = 0; i < n - 2; i++)
{
if (password.contains(username.substring(i, i + 3)))
{
weak = true;
break;
}
}
String res = (weak) ? "Weak password" : "Strong password";
System.out.println(res);
}
}

Output
Q6.
Code
import java.util.Scanner;

public class password_check


{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String username = sc.nextLine();


String password = sc.nextLine();
String confPassword = sc.nextLine();

if (username.equals("") || password.equals(""))
{
System.out.println("username and password cannot be empty");
}
if (password.length() < 8)
{
System.out.println("password should be min 8 chars in length");
}
if (password.contains(username))
{
System.out.println("Password should not contain username");
}
if (!password.equals(confPassword))
{
System.out.println("password and confirm password dont match");
}
}
}

Output
Q7.
Code
import java.io.*;
import java.util.*;
public class reverser
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String s = sc.nextLine(); //input


String[] sarr = s.split(" ");
String res = "";
for (String a : sarr)
{
StringBuilder sb = new StringBuilder(a);
res += sb.reverse() + " ";
}
System.out.println(res.trim());
}
}

Output
Q8.
Code
import java.io.*;
import java.util.*;
public class binary_hexa
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String s = sc.nextLine(); //assuming input is an integer in string


form
int n = Integer.parseInt(s);
System.out.println("decimal form : " + n);
String binForm = Integer.toString(n, 2);
System.out.println("Binary form : " + binForm);
String hexForm = Integer.toString(n, 16);
System.out.println("Hexadecimal form : " + hexForm);
}
}

Output

You might also like