Import Java
Import Java
Scanner;
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;
if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {
}
else {
newStr = newStr + ch;
}
}
System.out.println(newStr);
}
}
Assignment-3
import java.util.Scanner;
i = 0;
while(i < P.length) {
R[i] = P[i];
i++;
}
int j = 0;
while(j < Q.length) {
R[i++] = Q[j++];
}
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;
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);
}
03-08-22
15 21 -32 -41 54 61 71 -1
Sample Output: -32, -41, -19, 44, 15, 21, 54, 61, 71, 52
import java.util.Scanner;
System.out.println("Enter 10 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
System.out.println("Enter 20 numbers:");
for (i = 0; i < NUM_COUNT; i++) {
arr[i] = in.nextInt();
}
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] + " ");
}
}
}