Please open the menu to show more

Saturday, July 22, 2017

Solution for 22/July/2017 assignments

Solution for the 22/July/2017 assignments 

These code are implemented by


=> Pankaj kumar Gupta

=> BRANCH ECE

=> NIT, Arunachal pradesh



import java.util.*;

public class FrequencyOfWord {

public static void main(String[] arg) {

Scanner sc = new Scanner(System.in);
System.out.println("Enter your paragraph");

String str = sc.nextLine();

String[] data = str.split(" |\\,|\\.|\\!");
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;

for (String st : data) {

if (st.equalsIgnoreCase("is"))
a++;

if (st.equalsIgnoreCase("it"))
b++;

if (st.equalsIgnoreCase("the"))
c++;

if (st.equalsIgnoreCase("this"))
d++;

if (st.equalsIgnoreCase("that"))
e++;
}

System.out.println("Frequency Of 'is' =" + a);

System.out.println("Frequency Of 'it' =" + b);

System.out.println("Frequency Of 'the' =" + c);

System.out.println("Frequency Of 'this' =" + d);

System.out.println("Frequency Of 'that' =" + e);

}
}


=============================================================


import java.util.*;

public class ParaWordFrequency {

public static void main(String[] arg) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter your paragraph");
String str = sc.nextLine();

System.out.println("Enter word to search");
String word = sc.next();

int len = word.length();
int p = 0;

if (str.contains(word)) {

System.out.println("indexes");

for (int i = 0; i < ((str.length()) - len); i++) {

if ((str.substring(i, i + len)).equals(word)) {

p++;

System.out.print(i + "\t");
}
}

System.out.println("");
System.out.println("Frequency= " + p);

} else {
System.out.println("word not in paragraph\nfrequency of word is 0");
}

}
}


=============================================================


import java.util.*;

public class StringIntMaxMin {

public static void main(String[] arg) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter your text format integers");
String str = sc.nextLine();

String[] data = str.split(" ");

int temp = 0;
int max = 0;
int min = 100000;
for (String a : data) {
temp = Integer.parseInt(a);
// Checking for min
if (temp < min)
min = temp;
// Checking for max
if (temp > max)
max = temp;
}
System.out.println("Max in given input= " + max);
System.out.println("Min in given input= " + min);

}
}


=============================================================


import java.util.*;

public class ValidEmail {

public static void main(String[] arg) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter your email");
String str = sc.next();

int p = 0;
if (str.endsWith(".com") || str.endsWith(".co.in") || str.endsWith(".edu.in") ||                                   str.endsWith(".ac.in")) {

if (str.contains("..")) {
System.out.println("Invalid Email id");
} else {
for (int i = 0; i < ((str.length()) - 1); i++) {
if ((str.substring(i, i + 1)).equals(".")) {
p++;
}

}
if (p <= 2)
System.out.println("Valid Email id");
else
System.out.println("Invalid Email id");
}
} else
System.out.println("Invalid Email id");

}
}

No comments:

Post a Comment