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

Import Java

The program accepts student details like roll number, name, marks of 3 subjects from the user for multiple students and calculates the average marks. It then prints the student details along with their remark which is determined based on their average.
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)
19 views

Import Java

The program accepts student details like roll number, name, marks of 3 subjects from the user for multiple students and calculates the average marks. It then prints the student details along with their remark which is determined based on their average.
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/ 10

import java.util.

Scanner;

public class KboatAvgMarks


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter number of students: ");
int n = in.nextInt();

int rollNo[] = new int[n];


String name[] = new String[n];
int s1[] = new int[n];
int s2[] = new int[n];
int s3[] = new int[n];
double avg[] = new double[n];

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


System.out.println("Enter student " + (i+1) + "
details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
in.nextLine();
System.out.print("Name: ");
name[i] = in.nextLine();
System.out.print("Subject 1 Marks: ");
s1[i] = in.nextInt();
System.out.print("Subject 2 Marks: ");
s2[i] = in.nextInt();
System.out.print("Subject 3 Marks: ");
s3[i] = in.nextInt();
avg[i] = (s1[i] + s2[i] + s3[i]) / 3.0;
}

System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++) {
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ remark);
}
}
}

Assignment-2

import java.util.Scanner;

public class KboatVowelReplace


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();

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


char ch = str.charAt(i);

if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {

char nextChar = (char)(ch + 1);


newStr = newStr + nextChar;

}
else {
newStr = newStr + ch;
}
}
System.out.println(newStr);
}
}

Assignment-3

import java.util.Scanner;

public class Kboat3Arrays


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int P[] = new int[6];


int Q[] = new int[4];
int R[] = new int[10];
int i = 0;

System.out.println("Enter 6 elements of array P:");


for (i = 0; i < P.length; i++) {
P[i] = in.nextInt();
}

System.out.println("Enter 4 elements of array Q:");


for (i = 0; i < Q.length; i++) {
Q[i] = in.nextInt();
}

i = 0;
while(i < P.length) {
R[i] = P[i];
i++;
}

int j = 0;
while(j < Q.length) {
R[i++] = Q[j++];
}

System.out.println("Elements of Array R:");


for (i = 0; i < R.length; i++) {
System.out.print(R[i] + " ");
}
}
}

import java.util.Scanner;
public class palindromeWordsInSentence
{
public static void main(String[] args)
{
String sen="",wd="",wd1="";
char ch=' ',lastCharacter=' ';
int i=0,len=0;
Scanner sc = new Scanner(System.in);

System.out.println("Enter a sentence");
sen = sc.nextLine();
sen=sen+" ";
len=sen.length();
System.out.println("Palindrome words in sentence:");

for(i=0;i< len;i++)
{
ch=sen.charAt(i);
if(ch==' ')
{

if(wd.equalsIgnoreCase(wd1)==true)
{
System.out.println(wd);
}
wd1="";
wd="";

}
else
{
wd=wd+ch;
wd1=ch+wd1;
}
}

}
}
Q1.
Write a program to create three single dimensional arrays
cod[], pric[], qty[] to store product code, unit price and
quantity of each product for 10 products. Calculate the
total cost of each product and print the result in tabular
form including product code, unit price, quantity and total
cost of each product. At the end print total of price, total
of quantity and the total of costs.
Sol

import java.util.Scanner;

public class KboatProducts


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int cod[] = new int[10];
double pric[] = new double[10];
int qty[] = new int[10];

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


System.out.print("Enter code of product " + (i
+ 1) + ": ");
cod[i] = in.nextInt();
System.out.print("Enter unit price of product "
+ (i + 1) + ": ");
pric[i] = in.nextDouble();
System.out.print("Enter quantity of product " +
(i + 1) + ": ");
qty[i] = in.nextInt();
}

double tp = 0;
long tq = 0;
double tc = 0;

System.out.println("Code\tPrice\tQty\tCost");
for (int i = 0; i < 10; i++) {
double cost = qty[i] * pric[i];
tp += pric[i];
tq += qty[i];
tc += cost;
System.out.println(cod[i] + "\t" + pric[i] + "\
t" + qty[i] + "\t" + cost);
}

System.out.println("Total Price = " + tp);


System.out.println("Total Quantity = " + tq);
System.out.println("Total Costs = " + tc);
}
}

03-08-22

Write a program in Java to store 10 numbers (including


positive and negative numbers) in a Single Dimensional Array
(SDA). Display all the negative numbers followed by the
positive numbers without changing the order of the numbers.
Sample Input:

n[0] n[1] n[2] n[3] n[4] n[5] n[6] n

15 21 -32 -41 54 61 71 -1

Sample Output: -32, -41, -19, 44, 15, 21, 54, 61, 71, 52
import java.util.Scanner;

public class KboatSDANumbers


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

System.out.println("Enter 10 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}

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


if (arr[i] < 0)
System.out.print(arr[i] + ", ");
}

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


if (arr[i] >= 0)
System.out.print(arr[i] + ", ");
}
}
}

Write a program in Java to accept 20 numbers in a single


dimensional array arr[20]. Transfer and store all the even
numbers in an array even[ ] and all the odd numbers in
another array odd[ ]. Finally, print the elements of both the
arrays.
import java.util.Scanner;

public class KboatSDAEvenOdd


{
public static void main(String args[]) {

final int NUM_COUNT = 20;


Scanner in = new Scanner(System.in);
int i = 0;

int arr[] = new int[NUM_COUNT];


int even[] = new int[NUM_COUNT];
int odd[] = new int[NUM_COUNT];

System.out.println("Enter 20 numbers:");
for (i = 0; i < NUM_COUNT; i++) {
arr[i] = in.nextInt();
}

int eIdx = 0, oIdx = 0;


for (i = 0; i < NUM_COUNT; i++) {
if (arr[i] % 2 == 0)
even[eIdx++] = arr[i];
else
odd[oIdx++] = arr[i];
}

System.out.println("Even Numbers:");
for (i = 0; i < eIdx; i++) {
System.out.print(even[i] + " ");
}

System.out.println("\nOdd Numbers:");
for (i = 0; i < oIdx; i++) {
System.out.print(odd[i] + " ");
}
}
}

You might also like