CODE:
import java.util.Scanner;
public class JavaApplication3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println(“enter your name”);
String name=sc.nextLine();
System.out.println(“Enter your fee”);
int fee=sc.nextInt();
System.out.println(“Enter your rollno”);
int roll=sc.nextInt();
}
}
Output:
enter your name
Haseeb
Enter your fee
6000000
Enter your rollno
146
Task#2:
WAP that initializes 3 Strings.
- (i) Convert all 3 Strings.
- (ii) Convert S1 to uppercase .
- (iii) Find the String from concatenated String from 4 character to announced.
- (iv) Find the String from concatenated string from 2nd to 7th
- (v) Find index of String from concatenated string.
Input:
package javaapplication3;
public class NewClass1 {
public static void main(String[] args) {
String S1=”hasib”;
String S2=”Mangi”;
String S3=S1.concat(S2);
System.out.println(S1.toUpperCase());
System.out.println(S3);
System.out.println(S3.substring(4));
System.out.println(S3.substring(2,7));
System.out.println(S3.indexOf(S2));
}
}
Output:
HASEEB
hassibali
assibali
angi
5
Home Task:
WAP that take string st i\p attempting to guess to word enter letters one at a time after each guess the guess template is update to show which letters in the secret word match the letter guessed this process continuous until the guess template match the secret word of choice of 7 wrong attempts .the no of guesses is the output.
CODE:
import java.util.Scanner;
public class Hom {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner enter = new Scanner(System.in);
String word=”Haseeba”;
char [] guss={‘*’,’*’,’*’,’*’,’*’,’*’};
System.out.println(“guess the word”);
System.out.println(“You hava seven chance”);
int g=1,i=0,h=0,f=0;
while (g<=7){
System.out.println(“Enter a leter”);
String letter=enter.nextLine();
for(int k=0;k<word.length();k++){
if (letter.charAt(0)==word.charAt(k))
guss[k]=word.charAt(k);
i=k;
h++;
f++;
}
System.out.print(guss [k]);
}
System.out.println();
if (letter.charAt(0) != word.charAt(i)){
g++;
f++;
}
if(h==word.length()){
System.out.println(“you guess the word”);
System.out.println(“you have”+f+”number of guss”);
break;
}
if (g>7){
System.out.println(“You have more than 7 worng guesses”);
}
enter.close();
}
}
Output:
guess the word
You hava seven chance
******
Enter a leter
h
h*****
Enter a leter
a
ha****
Enter a leter
s
has***
Enter a leter
e
hase**
Enter a leter
e
haseeb*
Enter a leter
a
hasiba
you guess the word
you have 6 number of guss