Assignment: Assignment 1: Write A Program in Java To Print Hello World
Assignment: Assignment 1: Write A Program in Java To Print Hello World
Output:
java -cp /tmp/YWtpTKLfNX HelloWorld
Hello, World!
Output:
Enter three number to find sum:
5
69
8
The sum of three numbers are: 82
class Student4{
int id;
String name;
//creating a parameterized constructor
Student4(int i,String n){
id = i;
name = n;
}
//method to display the values
void display(){System.out.println(id+" "+name);}
Output:
*
* *
* * *
* * * *
* * * * *
* * * * * *
count);}}
Output:
Enter the string to calculate it’s length
Preetam singh
Total number of characters in a string:9
int
a[][]={{5,23,7},{23,44,43},{33,74,75}
}; int
b[][]={{6,64,7},{6,44,63},{31,42,54}}
;
System.out.println();//new line}}}
Output:
Assignment 10: Write a program to calculate the percentage of a
given student in the RTU exam. His marks from 5 subjects must
be taken as input from the keyboard, marks out of 80.
import java.util.*;
public class ass10{
public static void main(String args[]){
float a,b,c,d,e,per;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the marks of
subject-1:");
a=sc.nextInt();System.out.println("Enter the
marks of subject-2:"); b=sc.nextInt();
per = ((a+b+c+d+e)/400)*100;
System.out.println("your percentage is :"+per+"%");}}
Output:
Enter the maraks of subject-1
65
Enter the maraks of subject-2
45
Enter the maraks of subject-3
77
Enter the maraks of subject-4
88
Enter the maraks of subject-5
11
Your percentage is :57.2%
Assignment 11: Write a program to ask a user to enter his/her name
and gets output with hello “name”, have a good day.
import java.util.*;
public class ass11 {
public static void main(String[] args) { Scanner sc =new
Scanner(System.in); String name;
System.out.println("Enter your name");
name = sc.nextLine();
System.out.println("Hello,"+name+" have a good day!");}}
Output:
import java.util.*;
public class ass12 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String text;
System.out.println("Enter a string:");
text = sc.nextLine();
System.out.println(text.toLowerCase());}}
Output:
Assignment 10
Assignment 10
Assignment 13: Write a program to replace space with underscore.
mport java.util.*;
public class ass13
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String text;
System.out.println("Enter the text:");
text = sc.nextLine();
char ch = '_';
String text1 = text.replace(' ',ch);
System.out.println(text1);}}
Output:
Enter the text:
This is java lab
This_is_java_lab
Output:
Enter a year:
2000
It is a leap year
Assignment 15: Write a program to find out the type of website from
the URL: .com, .in, .org
import java.util.*;
public class ass15 {
public static void main(String[] args) {
String site;
System.out.println("Enter your
if(val)
Else
}
System.out.println("The entered elements of the array are :");
for(int i =0;i<5;i++){
System.out.println(a[i]+" ");
}
int n = a.length;
System.out.println();
if(check(a,n))
System.out.println("The array is sorted.");
else
Output:
Assignment 17: Create a class game, which allows a user to play “Guess the
number” game once
// Java program for the above
approach import java.util.*;
public class game1 {
// Function that implements the
int K = 5;
int i, guess;
System.out.println(
"A number is chosen"
+ " between 1 to 100."
// Iterate over K
Trials for (i = 0; i
< K; i++) {
System.out.println(
"Guess the number:");
// Take input for
guessing guess =
sc.nextInt();
// If the number is
guessed if (number ==
guess) {
System.out.println(
"Congratulation
s!"
+ " You guessed the number.");
break;}
else if (number > guess
&&i != K - 1) {
System.out.printl
n( "The number
is " "greater
than " +
guess);}
&&i != K - 1) {
System.out.print
ln( "The
number is"
if (i == K) {
System.out.println(
"You have exhausted"
+ " K trials.");
System.out.println(
"The number was " + number);}}
// Driver Code
public static
void
main(String
arg[])